[RESOLVED] getfenv and setfenv alternative?

Place to get help with not working mods / modding interface.
Post Reply
rater193
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Apr 19, 2017 10:37 pm
Contact:

[RESOLVED] getfenv and setfenv alternative?

Post by rater193 » Wed Apr 19, 2017 10:40 pm

Hello, i was wondering if there was a workaround for using getfenv and setfenv, so i can add support for letting users adding basic lua code to their machines. If i cant use get/setfenv, then it will expose all game functions to the user, winch i was wanting to limit that with those functions.
Last edited by rater193 on Sat Apr 22, 2017 8:53 pm, edited 2 times in total.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 2796
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: getfenv and setfenv alternative?

Post by DaveMcW » Thu Apr 20, 2017 1:31 am

The 4th argument to load() is what you want.

https://www.lua.org/manual/5.2/manual.html#pdf-load

rater193
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Apr 19, 2017 10:37 pm
Contact:

Re: getfenv and setfenv alternative?

Post by rater193 » Thu Apr 20, 2017 5:29 am

DaveMcW wrote:The 4th argument to load() is what you want.

https://www.lua.org/manual/5.2/manual.html#pdf-load
wow, that works :) lol thx, i know that they removed a few features specific to lua in their api, unfortunately, one of the more usefull ones was getfenv and setfenv :(

rater193
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Apr 19, 2017 10:37 pm
Contact:

Re: getfenv and setfenv alternative?

Post by rater193 » Thu Apr 20, 2017 5:32 am

DaveMcW wrote:The 4th argument to load() is what you want.

https://www.lua.org/manual/5.2/manual.html#pdf-load

how would i write to a file?

rater193
Burner Inserter
Burner Inserter
Posts: 10
Joined: Wed Apr 19, 2017 10:37 pm
Contact:

Re: getfenv and setfenv alternative?

Post by rater193 » Thu Apr 20, 2017 5:45 am

btw, i managed to get this to work :D

Code: Select all

/c local ret, err = load('local test = 1 print("load: "..tostring(load))', "", "bt", {["print"] = game.player.print, ["tostring"] = tostring})() game.player.print(tostring(ret)..", "..tostring(err))
im happy about that :P thx again for the help, i didnt know that load was a part of ACTUAL lua lol

Post Reply

Return to “Modding help”

Who is online

Users browsing this forum: AlmightyJu