lua-users home
lua-l archive

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



Hello,

I want to overload or extend an existing function (stored in the __index table) from a library. I want to do this from my C-program, NOT from Lua.

Maybe I don't see the woods for the trees, but how can I access this metatable and manipulate a function in it? I want to extend a certain function at the time of initializing (after opening the libraries) to connect this function call in Lua with a call of one of my own functions...

I think it must be something like that:


	lua_getglobal (L, LUA_LIBNAME); -- get the table of the library
	lua_pushstring (L, "functionname") -- push the name
	lua_pushcfunction (L, function) -- push the overloaded function
	lua_settable (L, -3) -- set it to the library table

...

I think this should overwrite the whole function with my own code. But I really want to extend the old function. Probably I need to call the old function from my new?!

Maybe somebody has already done something like that and has some hints or ideas for me?

Thanks a lot!
Bye
Eva