Original Post
Hi! I have recently started to experiment with LUA 5.1 and luabind. But I have encountered a problem that I can't solve. When I use luabind::call_function to call a lua function with a class as parameter the debugger gives me this error: Unhandled exception at 0x7c812a5b in LuaTest.exe: Microsoft C++ exception: luabind::error at memory location 0x0013fd4c.. Here is some example code that produces the error for me and the content of test.lua... Is it my code or should this work?
#include <iostream>
extern "C"
{
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
}
#include <luabind/luabind.hpp>
class Test
{
public:
void Print()
{
std::cout << "This is a test" << std::endl;
}
};
extern "C" int InitLuabind(lua_State* L)
{
using namespace luabind;
open(L);
module(L)
[
class_<Test>("Test")
.def(constructor<>())
.def("Print", &Test::Print)
];
return 0;
}
int main()
{
lua_State *L;
L = lua_open();
luaL_openlibs(L);
InitLuabind(L);
luaL_loadfile(L, "test.lua");
Test t;
luabind::call_function<void>(L, "test", &t); // Call function 'test' with t as parameter
system("pause");
return 0;
}
function test(e)
e:Print()
end