我的Lua脚本是由LOOP编译的,编译后的脚本模块在台式机(osx10.7.5)上运行良好。但是当我在Android phone (Android 2.3.6)上运行它时,它总是失败并抱怨attempt to call a string value。同样的脚本也可以在相同的手机中以脚本(未编译)的方式运行,而不会出现问题。
测试中使用了Lua 5.1.5和Android NDK r8b。
logcat中的错误:
12-26 09:40:26.934: E/libb22luapre(8190): Failed to run script: attempt to call a string valueC代码片段(为简单起见,删除了错误处理代码):
const char script[] = "require \"hello.world\"\n"
"require \"anothermodule\"\n"
"hello.world.test2()";
luaL_loadstring(L, script);
lua_pcall(L, 0, LUA_MULTRET, 0);我转储了预加载表,这些必需的模块已经存在(加载成功)。
我在网上搜索,仍然找不到解决方案。我们将非常感谢您的任何建议。
更新后,我编译了适用于android的lua命令,并将编译后的lua脚本嵌入其中。错误和上面的一样。
$ adb shell
$ cd /data/local
$ ls
tmp
lua
dump_preload.lua
$ ./lua dump_preload.lua
--- print table --- preload
test function: 0x376f0
anothermodule function: 0x37718
hello.world function: 0x376b0
--- print table --- loaded
string table: 0x33828
debug table: 0x37098
package table: 0x33d30
_G table: 0x32528
io table: 0x34e80
os table: 0x357b8
table table: 0x332c0
math table: 0x36530
coroutine table: 0x33988
--- print table --- loaders
1 function: 0x33ed8
2 function: 0x33ef8
3 function: 0x33f18
4 function: 0x33f38
$ ./lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> require 'test'
attempt to call a string value
stack traceback:
[C]: ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: ?
> require 'hello.world'
attempt to call a string value
stack traceback:
[C]: ?
[C]: in function 'require'
stdin:1: in main chunk
[C]: ?
> 发布于 2012-12-28 10:34:23
问题已解决。事实证明,编译后的lua代码是不可移植的。您必须在目标计算机上编译lua脚本。
以下是这些步骤的简短摘要:
https://stackoverflow.com/questions/14035361
复制相似问题