I want to thank you for your reply, this is useful information to me.
I am replying directly to you, because my mailserver has been bouncing
all lua-list mail the last week. My bounce-score went up to 4 out of 5.
I raised a support ticket at my hosting company. I have got your reply by
viewing the archives.
You'll notice 3 functions in this example:
- static int glfw_ReadImage( lua_State *L )
- static void pushGLFWImage_metatable( lua_State *L )
- static int glfw_GLFWImageGetSize( lua_State *L )
glfw_ReadImage constructs new userdata objects by pushing these on the
stack. It associates them with a metatable which handles OO-like
behavior, by pushing it on the stack using the pushGLFWImage_metatable
function. That function initializes the metatable if it does not yet
exist. It uses the __gc key of the metatable to call the free function
of glfw to take care of the image structure if it is no longer needed.
The glfw_GLFWImageGetSize method is an example for a method function.
It expects the first argument to be an userdata object with the
GLFWImage metatable. Then it's pushing the requested information from
that struct obtained from the userdata on the stack and returns them.
Last but not least, some Lua code how it's used:
tiles = glfw.ReadImage("tex/tiles.tga",0)
print("tex size: ",tiles:size())
Hope this clearifies it a bit on how to integrate OO methods through
the Lua API.