Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help with custom loadstring()?

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.

2 comments

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 :)

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.

1 answer

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

1 comment

0

Okay, thanks I'll try it.

This discussion is preserved as it was. New answers, comments, and votes are closed.