如何在 Lua 协程中调用 Java 函数?

我正在使用 luajava 开发一个游戏。当我在 lua 协程中调用 java 函数时,我会收到错误消息“无效的方法调用,没有这样的方法。”以下是代码:

在代码中,我推入了一个对象(People)到 luaState 中,并命名为“people”。在 lua 中,我打印“people”并两次打印“people.sayHello”。令人意外的是,我得到了不同的结果。我应该怎么做才能让它正常工作?感谢您的帮助!

原文链接 https://stackoverflow.com/questions/9759622

点赞
stackoverflow用户1527430
stackoverflow用户1527430

将下面翻译成中文并且保留原本的 markdown 格式

The colon is messing you up. There is no sayHello function with two arguments. By using a colon, you are sending 'self' (people) AND the string to the java code. You have no java method taking two arguments. Just use a dot instead of a colon in the Lua to make it work.

冒号让你误了方向。sayHello函数没有两个参数。使用冒号时,你把“self”(people)和字符串都发送给Java代码。你没有java方法可以传入两个参数。只需在Lua中使用一个点来替代冒号就可以正常工作。

2013-09-06 15:40:40