Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Help with custom loadstring()?

Asked by
LuaQuest 450 Moderation Voter
8 years ago

So I've heard some people talk about actually CREATING a custom loadstring function to load code locally (typically in script builder). Is this even possible? How would you be able to make your own loadstring function?

-- I know this could be totally wrong, but this is the only thing i could come close to
-- even though it's probably way off.

local http = game:GetService("HttpService")
local source = http:GetAsync("URL")

local function parse_string(str)
    local c = ''
    for i in str:gmatch(".")do
        c = c..'\\'..i:byte()
    end
    return c
end

local function load(str)
    local l = ''
    for i in str:gmatch('[^\\]+')do
        if tonumber(i) and string.char(tonumber(i)) then
            l = l..string.char(tonumber(i))
        end
    end
    return l
end

loadstring(load(parse_string(source)))()

Don't laugh, but that's about as close to anything that i'm going to get regarding making a custom loadstring function. If somebody could help, or offer just the slightest of advice, i would very much appreciate it.

And as always, thank you for your time.

1
Is there a reason why you would want this over the built in loadstring? Also keep in mind that usually functions like loadstring are super duper evil :) BlueTaslem 18071 — 8y
2
Well, I'm trying to make a script builder and i have sandboxing down. The only problem is, it would need client sided loadstring, or some form of executing code on a client. I just have no idea how it's possible. LuaQuest 450 — 8y

1 answer

Log in to vote
1
Answered by
Rhyles 80
8 years ago

Yes there is a way. What you need is a Lua bytecode interpreter, LBI for short. There should be a few online examples for you to edit. Although, if you want to make a Script Builder, you may need to create a custom error handler, as the ones provided on many open source interpreters are fairly uninformative. Let me know how you get on! :D

0
Okay, thanks I'll try it. LuaQuest 450 — 8y
Ad

Answer this question