如果我用常规.lua
文件编译luac
,可以在没有安装Lua库或解释器的情况下运行结果吗?
我很难尝试获取我的userInfo参考.我的一个方法是返回对象的实例.每次调用createUserInfo时,它都会将userInfoObject返回给lua.
但是,当我从Lua调用userInfo对象的方法时,我无法获取userInfo对象的引用(lua_touserdata(L,1))
static int getUserName (lua_State *L){
UserInfo **userInfo = (UserInfo**)lua_touserdata(L,1);
// The following is throwing null! Need help.
// Not able to access the userInfo object.
NSLog(@"UserInfo Object: %@", *userInfo);
}
static const luaL_reg userInstance_methods[] = {
{"getUserName", getUserName},
{NULL, NULL}
}
int createUserInfo(lua_State *L){
UserInfo *userInfo = [[UserInfo alloc] init];
UserInfoData **userInfoData = (UserInfoData **)lua_newuserdata(L, sizeof(userInfo*));
*userInfoData = userInfo;
luaL_openlib(L, "userInstance", userInstance_methods, 0);
luaL_getmetatable(L, "userInfoMeta");
lua_setmetatable(L, -2);
return 1;
}
// I have binded newUserInfo to …
Run Code Online (Sandbox Code Playgroud) 我使用 luac 来编译我的 lua 代码。luac版本是5.2.2,我的app原生lua是5.2.2。
我的lua代码
function hello()
print("hello test luac ")
end
hello()
Run Code Online (Sandbox Code Playgroud)
预编译代码:
1b4c 7561 5200 0104 0804 0800 1993 0d0a 1a0a 0000 0000 0000 0000 0001 0205 0000 0025 0000 0008 0000 8006 0040 001d 4080 001f 0080 0001 0000 0004 0600 0000 0000 0000 6865 6c6c 6f00 0100 0000 0100 0000 0300 0000 0000 0204 0000 0006 0040 0041 4000 001d 4000 011f 0080 0002 0000 0004 0600 0000 0000 0000 7072 696e 7400 0411 0000 …
我正在尝试实现一个简单的C++函数,它检查Lua脚本的语法.为此,我使用Lua的编译器函数luaL_loadbufferx()
并在之后检查其返回值.
最近,我遇到了一个问题,因为我认为应该被标记为无效的代码未被检测到,而是稍后脚本在运行时(例如,在lua_pcall()
)中失败.
示例Lua代码(可在官方Lua演示中测试):
function myfunc()
return "everyone"
end
-- Examples of unexpected behaviour:
-- The following lines pass the compile time check without errors.
print("Hello " .. myfunc() "!") -- Runtime error: attempt to call a string value
print("Hello " .. myfunc() {1,2,3}) -- Runtime error: attempt to call a string value
-- Other examples:
-- The following lines contain examples of invalid syntax, which IS detected by compiler.
print("Hello " myfunc() …
Run Code Online (Sandbox Code Playgroud) 多年来一直在Mac OS X通用二进制应用程序中使用Lua 5.0.Lua脚本使用luac编译,编译后的脚本与app捆绑在一起.他们在Tiger和Leopard,Intel或PPC中都能正常使用.
为了避免当时的库问题,我只是将Lua src树添加到我的Xcode项目中并按原样编译,没有任何问题.
是时候更新到更现代的Lua版本,所以我用5.1.4替换了源代码树.我使用make macosx重建了luac (机器在Intel上运行Leopard).
与往常一样,未编译的脚本在Tiger和Leopard,Intel和PPC中正常工作.
但是,现在编译的脚本无法在PPC计算机上加载.
所以我用'ansi'标志重建了luac,并重新编译了我的脚本.同样的错误.同样,'generic'的构建标志也没有产生任何乐趣.
谁能告诉我接下来能做些什么?
我有一个 lua 文件,当在 Notepad++ 中打开时,它会显示英文(未损坏)、可理解的文本的混合,以及“NULS”“ETX”和其他奇怪符号的混合,然后我深入尝试反编译它,我想弄清楚这是否可能?
任何帮助表示赞赏,谢谢。