Luabind: it is not possible to call basic lua functions like print, tostring

A very simple question I assume:

C ++ code calling lua looks like this:

lua_State* m_L;
m_L = lua_open();
luabind::open(m_L);
luaL_dofile(m_L, "test.lua");
try {
    luabind::call_function<void>(m_L, "main");
} catch (luabind::error& e) {
    std::string error = lua_tostring(e.state(), -1);
    std::cout << error << std::endl;
}
lua_close(m_L);

now test.lua has the following contents:

function main()
print "1"
end

After execution, I get an error message:

test.lua:2: attempt to call global 'print' (a nil value)

What is the problem? Does it have anything to do with the environment? I thought features like prints were defined in a global environment. Why is he not found then?

Many thanks.

+5
source share
1 answer

, luaopen_base, print . luaopen_string, luaopen_math, . , , Lua luaL_openlibs:

lua_State* m_L = luaL_newstate();
luaL_openlibs(m_L);
+6

All Articles