vLua: Loadstring reimplemented in Lua

Introduction

vLua is a drop-in batteries-included replacement to loadstring without restricted or crippled functionality.

API

vLua is super simple to use! Add the Module into your Project, then require it, that’s it. Here’s an example:

local loadstring = require(script.Loadstring)
loadstring("print'hi'")()

function loadstring(BytecodeOrSource: string, Environment: table): function

Takes BytecodeOrSource, and returns a executable function. BytecodeOrSource must be vanilla Lua 5.1, it currently does not accept Luau at this time, although this is being worked on by various members of the community. Optionally, you can provide a custom Environment for the returned function with the second variable.

Does this support Luau?

Currently, vLua only supports Lua 5.1 and does not support Luau in any format at this time. Progress toward support is being made by the community however, and you can follow the progress by visiting the following GitHub repositories:

What projects does vLua currently use?

How do I get it?

40 Likes

The Luaul link leads to a 404 page

1 Like

Whoopsies, that’s been fixed :slight_smile:

1 Like

It’s pretty amazing. But I am having trouble with this simple Event in the loadstring:

script.Parent.Touched:Connect(function(hit)
    print(hit)
end)

The event fires correctly but prints nil for every hit. I tried passing just a function name as the Connect parameter, but got the same results. The same thing happens with ClickDetector.MouseClick event The mouse click is supposed to return the player as a parameter, but it just comes back nil. Any advise?

SOLVED: Don’t fix the warning in FiOne about a table.move with index 0. Thought I would get rid of the script analysis warning and set it to 1. :crazy_face: But don’t do it. Works perfectly fine with the warning.

1 Like

It is most likely due to stack related issues.

Or the VM lacks or has a faulty “RETURN” opcode

I think LuauInLuau × Fiu is the best way to implement Loadstring with Luau support.
And I’ve made it: vLuau.
(Edit: Github)

4 Likes

Haven’t had a chance to actually test it, but took an initial look at this and wowie! That one large script! If you’re cool with it, I’ll take a crack at some point to break it down into various modules to make things a little more manageable, then integrate with vLua. I’d like add support for both vanilla Lua 5.1 and Luau some point down the road.

6 Likes

sadly it doesnt support the use of functions that have self (ex: f = {}
f:Add = function() end )

just causes a error instantly

i know this sounds weird and im sorry to bother but how would i disable the access of game datamodel and Instance.new() function and stuff?

1 Like

use metatables for the game datamodel, and set a global variable called Instance to this

Instance = { 
	new = function() 
		warn('disabled')
		
		return {}
	end,
	
	fromExisting = function()
		warn('disabled')
		
		return {}
	end,
}; 

i also highly recommend you restrict access to functions such as rawset, rawget, getfenv, setfenv, and so on.

3 Likes

Is it possible for me to require a module script from github?
this ends up giving me an error: require(loadstring(HttpService:GetAsync(“RobloxStudio-CodeHub/DiscordWebhookService.lua at main · CelestialDodo/RobloxStudio-CodeHub · GitHub”))())

There is a reason this is a loadstring re-make. You can’t actually use it, other than that, you should never do what you want to do. Just get the module in game

nvm, i got it to work, i wasnt using a raw url, and apparently wasnt supposed to use require

Im making a system on github that makes it easier for new people to make games, and as a test i put the code on github to see if it works, once im done the normal loadstring methods ill start to implement the loadstring remake, you can go onto the github page and see how its going so far if you want lol, so thats why i dont want to just put the module in my game

I think its a very bad idea to use loadstring for this, the request could fail making your game not work, other than that, it’s bad practice to depend on something always being the way it is; an update to a certain part of the code could cause obscure issues, or in a different case; the script could just backdoor the game at any moment! The entire point of having the modules in your game is so that doesnt happen, and when neccessary; update manually.

thats fine, i could use pcall with a delay just in case, plus, nothing ive ever done has been appreciated by anyone (except maybe my parents) so the chances of anyone except me using the stuff is pretty low anyway

really helpful thanks man! keep it up!

– says an exploiter

jkjkjk

|extracharacters

1 Like