I’m trying to get lua 5.1 to execute a line which is just a call to one of my c++ functions "Assail" I don’t understand why it does not work, can anybody point out the mistakes?
this is the Assail Function:
static int Assail(lua_State *L)
{
cout << "test" << endl;
return 1;
}
I’m trying to call do_string like this:
L = lua_open();
luaL_openlibs(L);
lua_register(L, "Assail", Assail);
luaL_dostring(L, "s = Assail()");
lua_close(L);
any help is appreciated.
Since you’re writing this in C++, name mangling is applied to the function, so it will have a special name in the final executable/library that is different from that Lua would expect. You can resolve this by changing its linkage to C using the
externkeyword: