As the title asks, how would I execute code in a string without using loadstring()? It would look like this:
str = [[
function foo(bool)
if bool then
print(bool)
end
end
foo(true)
]]
execute(str) -- prints true
I’ve tried manipulating the string by taking advantage of string patterns and functions and then storing them into a table in seperate functions and executing them all together, but that doesn’t seem to work. Any answer to my question would be appreciated.
The source code is over 5,000 lines, it was written by a Malaysian citizen somewhere around 2005-2007.
function luaU:make_setF(filename)
local buff = {}
buff.h = io.open(filename, "wb")
if not buff.h then return nil end
local writer =
function(s, buff) -- chunk writer
if not buff.h then return 0 end
if not s then
if buff.h:close() then return 0 end
else
if buff.h:write(s) then return 0 end
end
return 1
end
return writer, buff
end
I haven’t validated whether or not it is compatible with Roblox’s Luau but ‘io.open’ as seen in this snippet is unavailable.