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?

27 Likes

The Luaul link leads to a 404 page

Whoopsies, that’s been fixed :slight_smile:

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.

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)

2 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