Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC的代码怎么调用lua的某一个函数? #38

Open
slxgsy opened this issue Jun 26, 2016 · 3 comments
Open

OC的代码怎么调用lua的某一个函数? #38

slxgsy opened this issue Jun 26, 2016 · 3 comments

Comments

@slxgsy
Copy link

slxgsy commented Jun 26, 2016

看到demo里面有lua脚本调用oc函数的案例,但是反过来可以在oc代码里面直接调用lua 执行其中某一个函数吗? 没看到相关的代码。

另外demo中代码不完整:
2016-06-26 14:34:54.856 Demo[23080:758361] [LuaView][error] Not found Method: JHSLuaViewController.setLuaBox:
2016-06-26 14:38:07.796 Demo[23080:758361] [LuaView][error] Not found Method: JHSLuaViewController.externalApiDemo:number:
2016-06-26 14:38:07.796 Demo[23080:758361] [LuaView][error] Not found Method: JHSLuaViewController.externalApiDemo

@Zhaoyy
Copy link

Zhaoyy commented Jun 27, 2016

OC不懂,但是你可以参考Java:

public int luaFunc(int num) {
    LuaValue func = globals.get("luaFunc");

    if (!func.isnil()) {
      try {
        return func.call(CoerceJavaToLua.coerce(num)).toint();
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("func not found");
    }
    return 0;
  }

@dongxicheng
Copy link

LView.h头文件里面定义的两个API:
// 调用lua定义的全局函数,functionName:函数名; args:参数队列
-(NSString_) callLua:(NSString_) functionName args:(NSArray_) args;
或者:
// 获取lua定义的全局函数,name:函数名
-(LVBlock_) getLuaBlock:(NSString*) name;
这几个API暂时 IOS和安卓都不兼容,建议如果不是特殊情况不要使用

@Hero2000
Copy link

Hero2000 commented Jul 4, 2016

UIView+LuaView.h 里的

  • (void) lv_callLuaByKey1:(NSString*) key1;
    貌似也可以

    if( self.lv.l ) {
    lv_checkStack32(self.lv.l);
    [self.lv lv_callLuaByKey1:@"calllua"];
    }

window.callback{
calllua = function()
print("calllua ~~~~~~~~");
end,
};

我试了一下 也可以

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants