[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Meta function tables for LUA_FILEHANDLE: why two separate tables?
- From: Sean Conner <sean@...>
- Date: Wed, 16 Nov 2022 04:47:58 -0500
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
here:
https://github.com/spc476/lua-conmanorg/tree/master/src
> 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)
nil
Whereas having them all in the one metatable allows one to "access" these
functions:
> 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).
-spc