首页 > Lua可以用局部变量保存类方法吗?

Lua可以用局部变量保存类方法吗?

local GetBool = App.Config:GetBool

会不会有什么问题,类指针也会被保存?


可以的 Lua在线执行


不会,语法错误,
local GetBool = function(...) return App.Config:GetBool(...) end
or
local GetBool = App.Config.GetBool
local selfPtr = App.Config
GetBool(selfPtr, ...)



App.Config:GetBool() 表示执行GetBool函数
持有指针
App.Config.GetBool


保存的时候这么写:local GetBool = App.Config:GetBool
用的时候得这么玩:GetBool(App.Config, ...)
...是参数列表,应该知道。

【热门文章】
【热门文章】