lua-users home
lua-l archive

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


于 2012-6-16 8:07, Sven Olsen 写道:
  function game_wrapper_mt:__index(key)
    return self.__proto__[key]
  end

is that actually sufficient to make 
my_game:out("foo") 
reduce to 
__proto__.out(__proto__,"foo") ?

i don't use the ":" sugar much, but, i didn't think it was that sophisticated... shouldn't it just yield
__proto__.out( my_game ,"foo") ?

well, if you would only have one object, it's totally OK to leave out the `self' or `:' syntax,
and use the __proto__ as an upvalue

however, if you might have lots of objects to wrap, each with its own wrapper table, then you must store this
wrapper -> real object map somewhere, either internal (a field of self) or external (use a weak map table).