I am unable to include a Lua file in another Lua file. I am compiling Lua using C++ and LuaBridge. Here is my main function. Very very small.
lua_State* luaState = luaL_newstate();
luaL_openlibs(luaState);
luaL_dofile(luaState, "res/script.lua");
LuaRef mainFunction = luabridge::getGlobal("start", luaState);
try {
mainFunction();
} catch (const luabridge::LuaException& e) {
std::cout << e.what();
}
lua_close(luaState);
std::cin.get();
Here is my "script.lua" file:
mymathmodule = require("mymath")
main = function()
end
And the "mymath.lua" which is in the SAME directory.
mymath = {
add = function(a, b)
return a + b
end
}
return mymath
The program just crashes. Just removing the "mymathmodule = require("mymath")" line gives no error. What is the problem here??