Lua function crashes when comparing stored C++ object pointers using Luabind
snippet in lua
Lua function crashes when comparing stored C++ object pointers using Luabind
user4366
extern "C" {
#include "lua.h"
#include "lualib.h"
}
#include <luabind/luabind.hpp>
#include <luabind/operator.hpp>
class Obj {
};
bool operator==(const Obj& a, const Obj& b) {
return &a == &b;
}
int main(int argc, char **argv) {
lua_State* cLuaState = luaL_newstate();
luabind::open(cLuaState);
luaL_openlibs(cLuaState);
luabind::module(cLuaState) [
luabind::class_<Obj>("Obj")
.def(luabind::const_self == luabind::const_self)
];
luaL_dostring(cLuaState, "\
function func(v)\n\
print (\"Before: x is same as v?\")\n\
print (x == v)\n\
x = v\n\
print (\"After: x is same as v?\")\n\
print (x == v)\n\
end");
Obj* o = new Obj();
try {
luabind::call_function<void>(cLuaState, "func", o);
luabind::call_function<void>(cLuaState, "func", o);
} catch (std::exception &e) {
std::cout << "Exception thrown: " << e.what() << std::endl;
return 1;
}
return 0;
}