fix function ref
This commit is contained in:
parent
65c77d1621
commit
5e67c0d7e0
21
impl.lua
21
impl.lua
|
@ -3,7 +3,6 @@ env = IsDuplicityVersion() and "sv" or "cl"
|
|||
-- default (empty) constructor
|
||||
function Class:Init(...) end
|
||||
|
||||
|
||||
-- create a subclass
|
||||
function Class:extend(obj)
|
||||
local obj = obj or {}
|
||||
|
@ -39,7 +38,8 @@ function Class:extend(obj)
|
|||
-- allow for getters and setters
|
||||
mt.__index = function(table, key)
|
||||
local val = rawget(table._, key)
|
||||
if val and type(val) == "table" and (val.get ~= nil or val.value ~= nil) then
|
||||
--print(key, type(val))
|
||||
if val and type(val) == "table" and (rawget(val, '__cfx_functionReference') == nil) and (val.get ~= nil or val.value ~= nil) then
|
||||
if val.get then
|
||||
if type(val.get) == "function" then
|
||||
return val.get(table, val.value)
|
||||
|
@ -56,7 +56,7 @@ function Class:extend(obj)
|
|||
|
||||
mt.__newindex = function(table, key, value)
|
||||
local val = rawget(table._, key)
|
||||
if val and type(val) == "table" and ((val.set ~= nil and val._ == nil) or val.value ~= nil) then
|
||||
if val and type(val) == "table" and (rawget(val, '__cfx_functionReference') == nil) and ((val.set ~= nil and val._ == nil) or val.value ~= nil) then
|
||||
local v = value
|
||||
if val.set then
|
||||
if type(val.set) == "function" then
|
||||
|
@ -99,7 +99,6 @@ function Class:new(...)
|
|||
return obj
|
||||
end
|
||||
|
||||
|
||||
function class(attr)
|
||||
attr = attr or {}
|
||||
return Class:extend(attr)
|
||||
|
@ -138,7 +137,7 @@ function Impl:HookMethod(method, hookFn)
|
|||
if self.destroyed then
|
||||
return
|
||||
end
|
||||
local result = {pcall(hookFn, ...)}
|
||||
local result = { pcall(hookFn, ...) }
|
||||
local success = table.remove(result, 1)
|
||||
if not success then
|
||||
main:LogError("Impl %s hook %s error: %s", self.name, method, result[2])
|
||||
|
@ -221,6 +220,7 @@ if env == 'sv' then
|
|||
if not source then return main:LogError("param source missing") end
|
||||
return lib.callback.await(("%s_%s:%s"):format(impl, "cl", name), source, ...)
|
||||
end
|
||||
|
||||
function Impl:EmitNet(impl, name, source, ...)
|
||||
if type(impl) == "object" then
|
||||
impl = impl:GetName()
|
||||
|
@ -230,6 +230,7 @@ if env == 'sv' then
|
|||
if not source then return main:LogError("param source missing") end
|
||||
return TriggerClientEvent(("%s_%s:%s"):format(impl, "cl", name), source, ...)
|
||||
end
|
||||
|
||||
function Impl:Emit(impl, name, ...)
|
||||
if type(impl) == "object" then
|
||||
impl = impl:GetName()
|
||||
|
@ -247,6 +248,7 @@ else
|
|||
if not name then return main:LogError("param name missing") end
|
||||
return lib.callback.await(("%s_%s:%s"):format(impl, "sv", name), false, ...)
|
||||
end
|
||||
|
||||
function Impl:Emit(impl, name, ...)
|
||||
if type(impl) == "object" then
|
||||
impl = impl:GetName()
|
||||
|
@ -255,6 +257,7 @@ else
|
|||
if not name then return main:LogError("param name missing") end
|
||||
return TriggerEvent(("%s_%s:%s"):format(impl, "cl", name), ...)
|
||||
end
|
||||
|
||||
function Impl:EmitNet(impl, name, ...)
|
||||
if type(impl) == "object" then
|
||||
impl = impl:GetName()
|
||||
|
@ -266,19 +269,19 @@ else
|
|||
end
|
||||
|
||||
function Impl:LogInfo(msg, ...)
|
||||
main:LogInfo("[^6"..self.name.."^0] "..msg, ...)
|
||||
main:LogInfo("[^6" .. self.name .. "^0] " .. msg, ...)
|
||||
end
|
||||
|
||||
function Impl:LogError(msg, ...)
|
||||
main:LogError("[^6"..self.name.."^0] "..msg, ...)
|
||||
main:LogError("[^6" .. self.name .. "^0] " .. msg, ...)
|
||||
end
|
||||
|
||||
function Impl:LogSuccess(msg, ...)
|
||||
main:LogSuccess("[^6"..self.name.."^0] "..msg, ...)
|
||||
main:LogSuccess("[^6" .. self.name .. "^0] " .. msg, ...)
|
||||
end
|
||||
|
||||
function Impl:LogWarning(msg, ...)
|
||||
main:LogWarning("[^6"..self.name.."^0] "..msg, ...)
|
||||
main:LogWarning("[^6" .. self.name .. "^0] " .. msg, ...)
|
||||
end
|
||||
|
||||
function Impl:GetConfig()
|
||||
|
|
Loading…
Reference in New Issue
Block a user