lua-users home
lua-l archive

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


spir wrote:
> Hello,
> 
> thank you for you hints.
> 
> @ Per: If I understand correctly, I think your solution is more or
> less what I tried to do; if true, then this does not work because Lua
> file objects are userdata, not tables. For instance, storing the Lua
> file in a field and setting a metatable on my custom file objects such
> as {__index = File.method} with File.method = function(f,name) return
> f._luaFile[name] end precisely raises the  error above. (Indeed, the
> same happens with {__index = f._luaFile}.)

Hi, I think I explained it very poorly. I made a little test program, to test my solution the way I intended it. It did work for the super simple test case I made. My mail service seems to destroy my indentation for source files, so I have posted the solution here:

http://pastebin.com/f1a78b95a

I haven't tried it on other io functions that doesn't have object-oriented call style, or even other functions than just file:read(). I don't know if that would work. But I think this might be a good generic solution for subclassing classes that are represented in Lua as userdata. I'm new to Lua, so if there is something wrong with this solution, someone please enlighten me.... :)

Per