lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Kevin

Am 07.04.2014 11:28 schrieb Kevin Martin:
What is the output of print(type(getmetatable(mc)))

The output is a simple:

nil

I'm guessing LuaBridge isn't correctly detecting the type of p, and
thus isn't setting the proper metatable. The fact that you've
experienced the same problem with another binding leads me to believe
it may be a compiler issue?

Do you have access to a different compiler to try the code on?

I too am afraid this might be the case. I just ruled out LuaJit as a candidate. It happens with Vanilla Lua 5.1 as well. Unfortunately, this is a very large infrastructure here so swapping the compiler is not an option. Either it works with MSVC9 or my Lua evaluation has come to a harsh conclusion ;-)

Can I verify somehow if LuaBridge does the job?
Migt it be a DLL linkage error? MyClass does have a DLL interface with __declspec() declarators. Could this be an issue?


On a side note...
I still have hopes I might get the C API to work.

I did use this here:

int init_myclass(lua_State *L) {

	p = new MyClass();

	/* store the pointer to MyClass in global registry */
	lua_pushlightuserdata(L, (void *)&KeyToMyClass);  /* push address */
	lua_pushlightuserdata(L, ret);                   /* push value   */

	/* registry[&KeyToMyClass] = ret */
	lua_settable(L, LUA_REGISTRYINDEX);

	return 0;
}

and then have

int foo(lua_State *L) {

	/* retrieve the pointer to MyClass from registry */
	lua_pushlightuserdata(L, (void *)&KeyToMyClass);  /* push address */
lua_gettable(L, LUA_REGISTRYINDEX); /* retrieve value */ MyClass * mc = (MyClass *)lua_topointer(L, -1); /* convert to pointer*/
	mc->foo();

	return 0;
}

which works in Lua and allows me to call foo() but only after I have created using init_myclass(). I would still have to figure out how to pass the living object in there and continue to fail.





Cheers,
Moose