I want to make so that I can call lua functions from my C program but I dont know how to load the lua library.
So far I have tried to download all the lua source code from lua.org, and then put them into the same folder as my C program. And then included them in the C code.
How my code looks now:
#include "lua.h"
#include "lauxlib.h"
int main()
{
lua_State *L = luaL_newstate();
luaL_openlibs(L);
luaL_dofile(L, "test.lua");
return 0;
}
Error msg when compiling:
test.c: In function ‘main’: test.c:10:5: warning: implicit declaration of function ‘luaL_openlibs’ [->Wimplicit-function-declaration] luaL_openlibs(L); ^ In file included from test.c:5:0: lauxlib.h:122:24: warning: value computed is not used [-Wunused-value] (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) ^ test.c:11:5: note: in expansion of macro ‘luaL_dofile’ luaL_dofile(L, "test.lua"); ^ /tmp/ccHJTAY8.o: In function
main': test.c:(.text+0x9): undefined reference to
luaL_newstate' test.c:(.text+0x1e): undefined reference toluaL_openlibs' test.c:(.text+0x34): undefined reference to
luaL_loadfilex' test.c:(.text+0x5f): undefined reference to `lua_pcallk' collect2: error: ld returned 1 exit status