[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: userdata event tables?
- From: "J. Perkins" <jason@...>
- Date: Fri, 01 Feb 2002 16:27:36 -0500
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_newtable(L);
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
ptr.func()
And I get the error "attempt to index global 'ptr' (a userdata
value). But this works:
tbl = {}
eventtable(tbl, et)
tbl.func()
Is this a bug or a feature? Additionally, this Lua code:
eventtable(ptr, et)
fails with "bad argument #1 to 'eventtable' (table expected)"
Jason