Skip to main content
gamedev.net
🔒 Locked

luabind::call_function error

Started by JC-JuiCe 1 reply 2.7k views
Original Post
JC-JuiCe
JC-JuiCe
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

#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;
}

and the content of test.lua...

function test(e)
	e:Print()
end

Is it my code or should this work?
JC-JuiCe
JC-JuiCe
Nobody?
JC-JuiCe
JC-JuiCe
bump

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.