lua-users home
lua-l archive

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

Ahh, thanks for the heads up!  That should help keep things a bit cleaner. 

On Thu, May 3, 2012 at 11:40 PM, pansz <> wrote:
On Fri, May 4, 2012 at 3:04 AM, Andrew Budd <> wrote:
> Probably already obvious to most, but this is how I achieved the desired
> .prototype functionality
> lua_getglobal(L,"array");
> lua_pushstring(L,"prototype");
> luaL_getmetatable(L,"LuaBook.array");
> lua_settable(L,-3);
> at the bottom of the luaopen_array function

If you don't want to call a function, this is the obvious way to go.

But you really do not need to do getglobal(). Note that you need to
return 1 in your luaopen_array() function, this means the array table
is on the stack top.

when require "array", the global variable 'array' will be assigned
after luaopen_array() returned (with the return value in stack top),
it seems that you cannot get the global value of array inside luaopen_