lua-users home
lua-l archive

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


First there is a c++ class called target 
and it has a method called attack()

now i get a lua class to derive the 'target' class
~~~~~~~~~~~~~~~~~~~~~~~~~~~
class 'father' (target)
function father:__init()
end

function father:Act()
print('i'm father')
end

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now there is a method called GetTarget() in c++
returns a pointer of a 'target' 
but actually this pointer should be a 'father' but c++ didn't know
about lua classes
for actually this object is instanced by the construtor of father in lua
so i am wondering if  i can run the function of 'father' with this instance

~~~~~~~~~~C++ code~~~~~~~~~~~~~
// return a instance of father which instanced in lua and c++ didn't know it
target* GetTarget() ;

and registe here
def("GetTarget", &GetTarget)
~~~~~~~~~Lua code~~~~~~~~~~~~~~~
    target = GetTarget()
    target:Act() -- Act() is the method of father
                     -- how do lua know this target pointer is
actually a instance of father
                    -- so Act() can be called
                     -- is there something like <father>target  --
cast it to father?
~~~~~~~~~~~~~~~~~~~~~~~~~~~