lua 对象与 c++对象及互调

来源:互联网 发布:开淘宝店卖土特产 编辑:程序博客网 时间:2024/06/17 05:22

记录下别人的好的Blog链接

lua调用c++类对象这里写链接内容

lua调用lua类这里写链接内容

luaViewSDK 执行脚本堆栈

lvNewButton  luaD_precall  luaV_execute  luaD_call  f_call  luaD_rawrunprotected  luaD_pcall  lua_pcall  lv_runFunctionWithArgs  lv_runFunction  -[LuaViewCore runData:fileName:changeGrammar:]  -[LuaViewCore runData:fileName:]  -[LuaViewCore runFile:]  -[LuaView runFile:] 

oc代码

- (void) initlua{    NSString * str = [[NSBundle mainBundle] pathForResource:@"me" ofType:@"lua"];    CGRect cg = self.view.bounds;    cg.origin = CGPointZero;    self.lview = [[LView alloc] initWithFrame:cg];    self.lview.viewController = self;    [self.view addSubview:self.lview];    [self.lview runFile: str];}

lua代码

function createButton( text , x,y,w,h, callback)    local button = Button();    button:frame(x,y,w,h);    button:text(text);    button:backgroundColor(0xeeeeee);    button:callback( function()                    print("ok",button);                    if( callback ) then                    callback();                    end                    end);    return button;endbutton1 = createButton("测试",10,10,300,60);button3 = Button();button3:frame(10,250,100,100);button3:image("button0.png","button1.png");button3:callback(function()                local sourcestr = "This is a rainy day!";                local sourcelen = string.len(sourcestr);                local xxlen=button3:selected();                print("\nthe len of sourcestr is "..sourcelen);                print(xxlen);                if xxlen then                    button3:selected(false);                else                    button3:selected( true );                end                print("我是图片按钮2");end);

点击按钮取串长度调用层次, oc调用 lua库函数string.len的层次

lua_tolstring  luaL_checklstring  str_len  luaD_precall  luaV_execute  luaD_call  f_call  luaD_rawrunprotected  luaD_pcall  lua_pcall  lv_runFunctionWithArgs  lv_runFunction  -[NSObject(NSObjectLuaView) lv_buttonCallBack]  -[LVButton lvButtonCallBack] 

oc调用 lua, lua回调oc调用层次
如按钮, 调用按钮的点击消息,消息实体在lua中,lua会调用Button取是否按下属性,然后取反操作,通过lua来改变按钮的按下和弹起状态。

 selected  luaD_precall  luaV_execute  luaD_call  f_call  luaD_rawrunprotected  luaD_pcall  lua_pcall  lv_runFunctionWithArgs  lv_runFunction  -[NSObject(NSObjectLuaView) lv_buttonCallBack]  -[LVButton lvButtonCallBack] 

lua库函数加载及实现
linit.c中,有兴趣可以去解读下源代码

static const luaL_Reg lualibs[] = {  {"", luaopen_base},  {LUA_LOADLIBNAME, luaopen_package},  {LUA_TABLIBNAME, luaopen_table},  {LUA_IOLIBNAME, luaopen_io},  {LUA_OSLIBNAME, luaopen_os},  {LUA_STRLIBNAME, luaopen_string},  {LUA_MATHLIBNAME, luaopen_math},  {LUA_DBLIBNAME, luaopen_debug},  {NULL, NULL}};

lua原理介绍这里写链接内容

osx lua命令行安装这里写链接内容

duilib与lua结合这里写链接内容

探密 lua内部实现这里写链接内容

原创粉丝点击