#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int echohello()
{
printf("hello");
//return 1;
return 0;
}
int main()
{
lua_State* ls = luaL_newstate();
luaL_openlibs(ls);
lua_pushcclosure(ls, echohello, 0);
lua_setglobal(ls, "echohello");
luaL_dostring(ls,
"print('start call c function...')\r\n"
"echohello()\r\n"
"print('')"
"print('end call c function...')\r\n"
);
lua_close(ls);
return 0;
}
我假设你知道如何设置lua编译环境,如何链接lua库
我假设你使用的是c语言,并且知道函数调用的内部原理(不知道的话请不要像我这样把echohello给pushcclosure进去)

gcc下是一样的。