Lua调用c函数出错,以下是简单示例,为什么打印出来都是对的,但调用时就是nil #2029
Closed
sunny-sketch
started this conversation in
General
Replies: 4 comments 4 replies
-
用其它版本的lua库编译.so都是正常的,唯独用skynet自带的lua库编译就会遇到这个问题 |
Beta Was this translation helpful? Give feedback.
0 replies
-
把这个去掉试试 -L../skynet/3rd/lua |
Beta Was this translation helpful? Give feedback.
1 reply
-
@sniper00 只有先把table里的key全部转成小写才能正确调用,但实际打印出来table里的key本来就是小写 |
Beta Was this translation helpful? Give feedback.
0 replies
-
怀疑你链接了两个 luaVM 库 |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
myTest.c
#include <lua.h>
#include <lauxlib.h>
#include <stdio.h>
static int test1(lua_State *L)
{
printf("test1\n");
return 0;
}
extern int luaopen_myTest(lua_State *L)
{
luaL_Reg l[] = {
{"test1", test1},
{NULL, NULL}};
luaL_newlib(L, l);
return 1;
}
编译成.o的命令是gcc -g -Wall --shared -fPIC -o ../skynet/luaclib/myTest.so myTest.c -I../skynet/3rd/lua -I. -L../skynet/3rd/lua -llua
test.lua
local test=require"myTest"
for k, v in pairs(test) do
print(k, v)
end
test:test1();
打印出来是正确的,但是test:test()是空。
Beta Was this translation helpful? Give feedback.
All reactions