lua-users home
lua-l archive

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

Related to my earlier discussion of refs, I'm trying to set up a userdata to a table - that is, I want it's "index" tag handler to refer to a real lua table. In lua.c I added this code to create a userdata object and a table as globals.

	lua_newuserdatabox(L, ptr);
	lua_setglobal(L, "ptr");
	lua_setglobal(L, "et");

Then I set the event table on the user data

	lua_getglobal(L, "ptr");
	lua_getglobal(L, "et");
	lua_seteventtable(L, -2);

Then in Lua, I tried:

	et["index"] = et
	et["func"] = function() print("in func") end

And I get the error "attempt to index global 'ptr' (a userdata value). But this works:

	tbl = {}
	eventtable(tbl, et)

Is this a bug or a feature? Additionally, this Lua code:

	eventtable(ptr, et)

fails with "bad argument #1 to 'eventtable' (table expected)"