You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
例如lua里有如下定义
Account = {
balance = 10,
names=0,
[1] = 1,
[2.2] = 2.2,
}
function Account:withdraw (v)
self.balance = self.balance - v
end
function Account:new (o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function Account:show()
print("this is account show")
end
function Account:getBalance()
return self.balance
end
function Account:setBalance(val)
self.balance = val
end
function test6()
account = Account:new()
account.balance = 100
account.name = "sniperHW"
return account
end
C++的调用
try{
luaObject lo = luacpp::call<luaObject>(L,"test6");
lo.call<void>("show");
printf("balance:%d\n",lo.Get<int>("balance"));
lo.Set("balance",1000);
printf("balance:%d\n",lo.Get<int>("balance"));
printf("1:%d\n",lo.Get<int>(1));
printf("2:%f\n",lo.Get<double>(2.2));
}catch(std::string &err)
{
printf("%s\n",err.c_str());
}
C++这边能直接创建luaObject对象吗?
如果可以
luaObject(lua_State *lState,int index)
index是什么意思
The text was updated successfully, but these errors were encountered: