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 » Scripting Helpers
Home Search
 

Re: How can you give loadstring() local arguments?

Previous Thread :: Next Thread 
kayaven is not online. kayaven
Joined: 01 Jun 2011
Total Posts: 30
30 Jun 2013 08:58 AM
How?
Report Abuse
rabbidog is not online. rabbidog
Joined: 27 Jun 2011
Total Posts: 804
30 Jun 2013 09:07 AM
Run it in a localscript.
Report Abuse
kayaven is not online. kayaven
Joined: 01 Jun 2011
Total Posts: 30
30 Jun 2013 09:18 AM
Is there an other way, like

a = "hello"
function(a) loadstring(print(a)) end


this doesnt work, is there some other way that you just gave me?
Report Abuse
kayaven is not online. kayaven
Joined: 01 Jun 2011
Total Posts: 30
30 Jun 2013 09:37 AM
Nevermind, finally found out :D
Report Abuse
rabbidog is not online. rabbidog
Joined: 27 Jun 2011
Total Posts: 804
30 Jun 2013 12:47 PM
How?
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
30 Jun 2013 12:50 PM
Here's how I did it in my free time:

function runCodewithVariables(code, vars)
local func = loadstring(code)
local env = getfenv(func)
for i, v in pairs(vars) do env[i] = v end
return setfenv(func, env)()
end

print(runCodewithVariables("print(var1) return something", {var1="Hi everyone", something="HI"}))

It is innefficient, yes. But I was half asleep at the time, so I just did that.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
30 Jun 2013 12:51 PM
Loadstring returns a variadic function.


local a, b, c = loadstring("return ...")(1, 2, 3)
print(a, b, c)
--> 1 2 3
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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