lua-users home
lua-l archive

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

I'm trying to create a global userdata object called "Connection" and
then add a metatable to it so I can perform operations like

Here's what I'm doing...

1) Create new metatable (luaL_newmetatable)
2) Push "__metatable" (string) onto the stack.
3) Create a copy of my metatable and push on the stack (lua_pushvalue -2)
4) Perform settable (so myMetatable.__metatable is equal to myMetatable)
5) Use luaL_openlib to assign methods/functions to the metatable.
6) Push "Connection" (string) onto the stack.
7) Push light userdata onto the stack.
8) Get a copy of the metatable and push it onto the stack  (luaL_getmetatable)
9) Set my userdata's metatable equal to the metatable we just pulled 
(using lua_setmetatable)
10) Assign my light userdata to the globals table.

The error I'm getting is "attempt to index global 'Connection' (a
userdata value)

If I'm doing something wrong, can somebody explain how to simply set
the metatable of a userdata so I can create functions?