【问题标题】:Lua Error: "attempt to call a string value" under Android NDK?Lua 错误:Android NDK 下的“尝试调用字符串值”?
【发布时间】:2012-12-11 16:52:29
【问题描述】:

我的 Lua 脚本由LOOP 编译,编译后的脚本模块在台式机(OSX 10.7.5)中运行良好。但是当我在Android手机(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 value

C 代码 sn-p(为简单起见,删除了错误处理代码):

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]: ?
> 

【问题讨论】:

    标签: android android-ndk lua


    【解决方案1】:

    问题已解决。事实证明,编译后的 lua 代码不可移植。您必须针对目标机器编译 lua 脚本。

    步骤的简短摘要:

    1. 为 Android 编译 lua 命令
    2. 将 lua 命令文件和 LOOP 的 lua 文件以及应用程序的 lua 文件推送到目标手机的文件夹中,例如 /data/local
    3. 打开 adb shell 并编译 lua 脚本文件
    4. 拉出生成的.h.c文件

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 1970-01-01
      • 2015-04-28
      • 2017-04-06
      • 2019-01-06
      • 2015-06-15
      • 1970-01-01
      • 2016-06-21
      • 2011-07-30
      相关资源
      最近更新 更多