Skip to content
Vurv edited this page Feb 15, 2021 · 2 revisions

Last updated for version v0.3.1

Main Info

This is a sub-addon in VExtensions that deals with running E2 code inside of E2. It comes with functions like try and runString.
If you find any bugs, please report them to the Issues page.

Documentation

Functions

t = try(s func_name)

Tries to find a user defined function with the name / func_name, then runs it in a safe environment.
Returns a table with this structure:

function a(){error("cool")}
try("a") == table(
    [1] = 0,
    [2] = "cool"
)

[1] Being whether the code ran successfully,
[2] Being the error string if it did error.

t = try(s func_name, t args)

Same as try(s), however it passes a table as an argument to the function you are attempting to call.
This means the function you're trying to call needs to take a table as it's only argument.

runString(s code)

Runs the E2 code given, in the same context of the chip it is called from.
Be aware that people can call literally anything inside there, and so you shouldn't allow others to input random code.
For example, they could call while(1){} and kill your chip, or concmd which would run concommands on YOUR CLIENT. This runs in unsafe mode, which means if the code errors in any way it will error the parent chip.

s = runString(s code, n safe_mode)

This is the same as runString(s), however it has an option to run it in safe_mode.
If you pass anything but 0 to safe_mode, then it will run the code and if it encountered an error, it will return the error as a string.
Keep in mind this will not prevent errors from infinite loops, cpu cost, etc.

Example

@name RunE2 Example
print( runString("error(\"test\")", 1) ) #--> "test"

See more in-depth examples in our Discussions