Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/client/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,22 @@
---@class OxPlayerClient : OxClass
local OxPlayer = lib.class('OxPlayer')

-- Support for `player.method` rather than self (:) syntax
-- Support both obj.method() and obj:method() calling conventions.
-- The closure captures self, so : syntax passes an extra self as first arg.
function OxPlayer:__index(index)
local value = OxPlayer[index] --[[@as any]]

if type(value) == 'function' then
self[index] = value == OxPlayer.__call and function(...)
return value(self, index, ...)
end or function(...)
return value(self, ...)
self[index] = value == OxPlayer.__call and function(first, ...)
if first == self then
return value(self, index, ...)
end
return value(self, index, first, ...)
end or function(first, ...)
if first == self then
return value(self, ...)
end
return value(self, first, ...)
end

return self[index]
Expand Down
16 changes: 12 additions & 4 deletions lib/server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ function OxPlayer:__index(index)
local value = OxPlayer[index] --[[@as any]]

if type(value) == 'function' then
self[index] = value == OxPlayer.__call and function(...)
return value(self, index, ...)
end or function(...)
return value(self, ...)
-- Support both obj.method() and obj:method() calling conventions.
-- The closure captures self, so : syntax passes an extra self as first arg.
self[index] = value == OxPlayer.__call and function(first, ...)
if first == self then
return value(self, index, ...)
end
return value(self, index, first, ...)
end or function(first, ...)
if first == self then
return value(self, ...)
end
return value(self, first, ...)
end

return self[index]
Expand Down
16 changes: 12 additions & 4 deletions lib/server/vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ function OxVehicle:__index(index)
local value = OxVehicle[index] --[[@as any]]

if type(value) == 'function' then
self[index] = value == OxVehicle.__call and function(...)
return value(self, index, ...)
end or function(...)
return value(self, ...)
-- Support both obj.method() and obj:method() calling conventions.
-- The closure captures self, so : syntax passes an extra self as first arg.
self[index] = value == OxVehicle.__call and function(first, ...)
if first == self then
return value(self, index, ...)
end
return value(self, index, first, ...)
end or function(first, ...)
if first == self then
return value(self, ...)
end
return value(self, first, ...)
end

return self[index]
Expand Down