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