Skip to content

Commit

Permalink
Add provisions for directly receiving buffers (#41)
Browse files Browse the repository at this point in the history
Just a commit to support passing buffers because people with buffers
will have their data go through a round trip with writestring and
readstring
  • Loading branch information
dyslexicsteak authored Jun 3, 2024
1 parent 9fac732 commit 2cd422e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Source.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local coroutine_resume = coroutine.resume
local coroutine_close = coroutine.close

local buffer_fromstring = buffer.fromstring
local buffer_len = buffer.len
local buffer_readu8 = buffer.readu8
local buffer_readu32 = buffer.readu32
local buffer_readstring = buffer.readstring
Expand Down Expand Up @@ -198,7 +199,7 @@ local function luau_deserialize(bytecode, luau_settings)
luau_validatesettings(luau_settings)
end

local stream = buffer_fromstring(bytecode)
local stream = if type(bytecode) == "string" then buffer_fromstring(bytecode) else bytecode
local cursor = 0

local function readByte()
Expand Down Expand Up @@ -530,7 +531,7 @@ local function luau_deserialize(bytecode, luau_settings)

local mainProto = protoList[readVarInt() + 1]

assert(cursor == #bytecode, "deserializer cursor position mismatch")
assert(cursor == buffer_len(stream), "deserializer cursor position mismatch")

mainProto.debugname = "(main)"

Expand All @@ -551,7 +552,7 @@ local function luau_load(module, env, luau_settings)
luau_validatesettings(luau_settings)
end

if type(module) == "string" then
if type(module) ~= "table" then
module = luau_deserialize(module, luau_settings)
end

Expand Down

0 comments on commit 2cd422e

Please sign in to comment.