lua-users home
lua-l archive

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

sorry about that. the code in my last post is incorrect. 
one possible working __index function might be like this:


Excellent, this worked and is in fact a much more full solution than I need -> I will only be creating one instance of game_wrapper and I am only calling functions in the game object, not retrieving data. I tried a solution similar to the one you gave with no luck. The innovation that I wasn't aware was possible//didn't think of was to pass back a function block with a parameter structure already built in, very clever. You have my thanks.

For completion, I include the full script below:-

local game_wrapper = {}
local game_wrapper_mt = {}

function game_wrapper_mt:__index(key)
local proto = rawget(self, "__proto__")
local field = proto and proto[key]

if type(field) ~= "function" then
return field
return function (obj, ...)
if obj == self then
return field(proto, ...)
return field(obj, ...)

function game_wrapper:new()
return setmetatable({__proto__ = game}, game_wrapper_mt)

my_game = game_wrapper:new()
my_game:out("This text should appear in the debug console like as if I'd called game:out()!")