• Lua integration problems
    1 replies, posted
Okay, I want to integrate Lua into my program. I have downloaded LuaDist(which contains the C headers, tons of DLLs and what not). I've unpacked it from it's .zip file. I've done 'extern "C"' and included all the necessary headers, yet not a single "lua_" function will work. This is the format of errors I get upon attempting to compile my c++ code: [code][Linker error] C:\Users\<name redacted>\AppData\Local\Temp\cc4ZnwXr.o:test_lua.cpp:(.text+0x16): undefined reference to `lua_<function name here>'[/code] This is the code itself: [code]#include <iostream> #include "lua.hpp" lua_State* L; int testing_func( lua_State *L ) { // Create a number from our argument double num = lua_tonumber( L, 1 ); // Made a double purely for precision purposes, in case our lua // argument is a float (and lua_tonumber accepts a double only, anyways) lua_pushnumber( L, num + 1 ); return 1; }; void report_errors(lua_State *L, int status) { if ( status!=0 ) { std::cerr << "-- " << lua_tostring(L, -1) << std::endl; lua_pop(L, 1); // remove error message } } int main(int argc, char** argv) { for ( int n=1; n<argc; ++n ) // loop through to get various lua files we've made { const char* file = argv[n]; lua_State *L = lua_open(); luaopen_io(L); luaopen_base(L); luaopen_table(L); luaopen_string(L); luaopen_math(L); lua_register( L, "AddToNum", testing_func ); std::cerr << "Loading file: " << file << std::endl; int s = luaL_loadfile(L, file); if ( s==0 ) { // execute Lua program s = lua_pcall(L, 0, LUA_MULTRET, 0); } report_errors(L, s); lua_close(L); std::cerr << std::endl; } return 0; }[/code] What happened? I haven't made any .lua files as I wanted to test this out, is that the problem or is something else causing this?
Feeding it headers isnt enough, you have to link the lua lib file.
Sorry, you need to Log In to post a reply to this thread.