lua-users home
lua-l archive

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

It was thus said that the Great bil til once stated:
> ... sorry, I forgot the title in last post ... here exact copy again
> with title...
> Hi, I am just "fighting" with designing some new libs for Lua.
> I found, that liolib.c from Lua source is a very instructive lib for
> showing how to install the meta stuff, as it even includes the io lib
> together with a further metatype LUA_FILEHANDLE.

  If you want to see some mor Lua libs, I have written quite a few, most are

> The function table for the file handles is strangly separated into
> "new fuctions" and "standard meta functions":
> In the function create meta, these two tables are then somehow
> combined as I see it:
> Why not use just ONE table for all meta methods, as e. g. the following table:

  I'm not sure.  Most of my modules mix both and set the __index field to
the metatable itself.  I suppose one reason is to prevent accessing the meta
functions themselves.  

> print(io.stdout.close)
function: 0x8066b1c
> print(io.stdout.__index)

Whereas having them all in the one metatable allows one to "access" these

> pollset = require "org.conman.pollset"
> x = pollset()
> print(x.insert)
function: 0x302273
> print(x.__index)
table: 0x95b4a48

and thus, they could be called from user code directly, or allow easy access
to the metatable in a sandboxed environment (i.e. no getmetatable() or
setmetatable() function).