mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +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
|
||||
- [x] Server callbacks
|
||||
- [x] Table utilities
|
||||
- [x] OxMySQL wrapper (might scrap for oxmysql v2.0.0)
|
||||
- [x] Streaming exports
|
||||
- [x] Metatable packing/unpacking
|
||||
- [x] SetInterval
|
||||
|
||||
#### To do
|
||||
|
||||
22
init.lua
22
init.lua
@@ -71,30 +71,8 @@ import = setmetatable({}, {
|
||||
})
|
||||
|
||||
local lib = {}
|
||||
local msgpack_new = msgpack.new
|
||||
local msgpack_unpack = msgpack.unpack
|
||||
local getmetatable = getmetatable
|
||||
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, {
|
||||
__index = exports[LIBRARY],
|
||||
|
||||
|
||||
Reference in New Issue
Block a user