This is something I want to do in C++ using the Lua C API.
I'm trying to figure out a good way to make userdata derive from a base userdata object.
I want to be able to do this:
local item = me:GetCurrentItem()
print(item:GetPos())
instead of:
local item = me:GetCurrentItem()
print(item:GetBaseObject():GetPos())
In these examples, me:GetCurrentItem() returns userdata with some functions, but it lacks the base functions which item:GetBaseObject() returns.
I'm binding Lua in the Crysis Wars SDK for learning purposes. The SDK provides an interface to the base entity which is a struct. The IItem struct (me:GetCurrentItem()) is the same. Since these are structs I can't cast them to the base struct or call its base functions. I have to use the IEntity *GetEntity() function.
I've tried chaning the self pointer in __index but it causes the local variable "item" to become "entity" which is kinda obvious, but I want it to revert back after calling the GetPos function, which seems illogical somehow.
Does anyone have a good solution to this issue?