generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Textbox that executes code that you type in it?

Previous Thread :: Next Thread 
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
11 Nov 2016 12:52 AM
Ok, here's a pattern I'm going to use:

local api = require([path to api module])
local env = {api=api}

-- manually add safe functions
-- lua-users wiki has a relevant page titled SandBoxes
env.tostring = tostring
...

local func = loadstring([string with user script])
setfenv(func, env)
func()

Is it true that setfenv works like setmetatable in that func will use env as it's environment even if called in different scope?
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:54 AM
local function loadsafestring(code,env)
local func=loadstring(code)
setfenv(func,env)
return func
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Nov 2016 12:55 AM
it'd only be truly safe if you make sure to sandbox getfenv among a couple of other things
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
11 Nov 2016 12:56 AM
I won't add them to the environment in the first place
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 12:59 AM
I think setfenv replaces the environment table and not the metatable
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 01:00 AM
get rid of dat and ^
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 01:03 AM
you can check by using rawget on the environment or next/pairs
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
11 Nov 2016 01:04 AM
"I think setfenv replaces the environment table and not the metatable"
That doesn't make sense. It replaces the whole table and the metatable is attached to that table. You overwrite the env you lose the table and thus it's metatable.
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 01:06 AM
yea i said to remove "and"

'it replaces the environment table not the metatable'
as in it sets the table to use as the environment
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 01:06 AM
not just the metatable** lol
Report Abuse
Wunder_Wulfe is online. Wunder_Wulfe
Joined: 13 Sep 2016
Total Posts: 8356
11 Nov 2016 01:08 AM
if you want to mimic the way roblox does it to not confuse any scripts you could
setfenv(func,setmetatable({},{__metatable="This metatable is locked";__index=myEnvironment}))
Report Abuse
DaCrazyDev is online. DaCrazyDev
Joined: 28 Sep 2013
Total Posts: 134
11 Nov 2016 12:40 PM
@Wunder_Wufle

A little help, please!!

I get an error that says

"loadstring() is not available", but I already have the option enabled
Report Abuse
VilgO is not online. VilgO
Joined: 15 Feb 2011
Total Posts: 518
11 Nov 2016 03:06 PM
Are you sure you're calling it from a server script, not a LocalScript?
http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#loadstring
Report Abuse
Previous Thread :: Next Thread 
Page 3 of 3Go to page: 1, 2, [3] Prev
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image