lua-users home
lua-l archive

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


Per Bull Holmen wrote:
> spir wrote:
> > I'm looking for a way to "subtype" Lua files, for file objects to
> > hold additional attributes. It seems I cannot directly set
> > attributes on Lua Files, since they are userdata. Is there a way to
> > write a custom file type that delegates file methods to an actual
> > Lua file (open in mode 'r')? My trials using __index with a table or
> > function launch errors like:
> 
> Perhaps you can write your factory function so that each new instance
> contain the corresponding Lua file (hold a reference to it), rather
> than deriving from it? Then your __index function could replace self
> with the reference to the original file.

Sorry... I'm new to Lua, I forgot that the __index function can't do that directly. But maybe it could query the "real" file for the key, check if it points to a function, and if it does, return an anonymous wrapper function that replace self with the original file.... ?? I don't know if you can do that, so I should shut up now, untill I know Lua better... :)

Per