我有一個定義如下:如何申請LUA定義
#define namef (s, r, x) (p_name ((s), (r), (x)))
我的文件Lua是如下:
tbl= {
name_func = module;
};
我的代碼如下:
void getname(void) {
lua_State *L = luaL_newstate();
luaL_openlibs(L);
char *arc = "luafun.lua";
if (luaL_dofile(L, arc)) {
printf("Error in %s", arc);
return;
}
lua_getglobal(L, "tbl");
lua_getfield(L, -1, "name_func");
namef(r_name, lua_tostring(L, -1), sizeof(r_name));
lua_close(L);
printf("done");
}
r_name是一個陣列char r_name [11];
bu牛逼它給了以下錯誤:
PANIC: unprotected error in call to Lua API (attempt to index a nil value)
我不知道爲什麼這是發生在C正常工作,更要改變LUA錯誤發生
什麼是'p_name'? – 2015-11-05 01:53:00
這不是一個函數,它是一個靜態數組聲明。你顯然不能稱它爲一個函數。 – 2015-11-05 02:16:20
更多有什麼方法可以使用lua獲取價值? – Chozie