mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-19 07:56:02 +01:00
Revert "feat(init): add custom packing for metatables"
This reverts commit 1ad137b8c5.
Prefer native solutions, this is too niche.
This commit is contained in:
@@ -17,9 +17,7 @@ Any resources distributed with this code is subject to the same license restrict
|
|||||||
#### Currently implemented
|
#### Currently implemented
|
||||||
- [x] Server callbacks
|
- [x] Server callbacks
|
||||||
- [x] Table utilities
|
- [x] Table utilities
|
||||||
- [x] OxMySQL wrapper (might scrap for oxmysql v2.0.0)
|
|
||||||
- [x] Streaming exports
|
- [x] Streaming exports
|
||||||
- [x] Metatable packing/unpacking
|
|
||||||
- [x] SetInterval
|
- [x] SetInterval
|
||||||
|
|
||||||
#### To do
|
#### To do
|
||||||
|
|||||||
26
init.lua
26
init.lua
@@ -46,8 +46,8 @@ local function loadFile(self, file)
|
|||||||
else error(('\n^3Unable to import module (%s)^0'):format(dir), 3) end
|
else error(('\n^3Unable to import module (%s)^0'):format(dir), 3) end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Loads a module from the library.
|
--- Loads a module from the library.
|
||||||
---If the module has already been loaded then it will reference the existing chunk.
|
--- If the module has already been loaded then it will reference the existing chunk.
|
||||||
---@param file string
|
---@param file string
|
||||||
---@return table
|
---@return table
|
||||||
local function getImport(self, file)
|
local function getImport(self, file)
|
||||||
@@ -71,30 +71,8 @@ import = setmetatable({}, {
|
|||||||
})
|
})
|
||||||
|
|
||||||
local lib = {}
|
local lib = {}
|
||||||
local msgpack_new = msgpack.new
|
|
||||||
local msgpack_unpack = msgpack.unpack
|
|
||||||
local getmetatable = getmetatable
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
---@param tbl table
|
|
||||||
--- packs a table and metatable with msgpack
|
|
||||||
function lib.pack(tbl)
|
|
||||||
local userdata = msgpack_new()
|
|
||||||
userdata:_table(tbl)
|
|
||||||
|
|
||||||
local mt = getmetatable(tbl)
|
|
||||||
if mt then userdata:table(mt) end
|
|
||||||
|
|
||||||
return tostring(userdata), not mt and true
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param data string
|
|
||||||
--- unpacks a msgpack table and metatable
|
|
||||||
function lib.unpack(data)
|
|
||||||
local tbl, mt = msgpack_unpack(data)
|
|
||||||
return mt and setmetatable(tbl, mt) or tbl
|
|
||||||
end
|
|
||||||
|
|
||||||
setmetatable(lib, {
|
setmetatable(lib, {
|
||||||
__index = exports[LIBRARY],
|
__index = exports[LIBRARY],
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user