I wound like to provide my program with "class" ability. And the lua class can receive "event" from program.
Following example, My program random to rob money in account. How can I call "Account:Robbed" in my c++ code?
(ResisterEvent is provide from c++)
Code in lua.
Account = {};
Account.__index = Account;
function Account.Create( balance )
local acnt = {}; -- our new object
setmetatable( acnt,Account ); -- make Account handle lookup
acnt.balance = balance; -- initialize our object
return acnt;
end
function Account:Withdraw( amount )
self.balance = self.balance - amount
end
function Account:Robbed( amount )
self.balance = self.balance - amount
end
-- create and use an Account
acc = Account.Create( 1000 )
acc:Withdraw( 100 )
ResisterEvent( acc.Robbed );