[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Simple (?) question about metatables and userdata
- From: John Klimek <jklimek@...>
- Date: Thu, 15 Dec 2005 11:09:28 -0500
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
10) Assign my light userdata to the globals table.
The error I'm getting is "attempt to index global 'Connection' (a
If I'm doing something wrong, can somebody explain how to simply set
the metatable of a userdata so I can create functions?