2tallhank
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 2075 |
|
|
| 25 May 2013 04:46 PM |
Like what it does?
And maybe give me an example? |
|
|
| Report Abuse |
|
|
|
| 25 May 2013 04:47 PM |
http://wiki.roblox.com/index.php/Tostring#loadstring
expect me |
|
|
| Report Abuse |
|
|
|
| 25 May 2013 04:49 PM |
It interprets a string as Lua code and returns it as a function.
Example:
local str = "print('hello world')" local func = loadstring(str) func()
Or you could could run it outside of a variable:
local str = "print('hello world')" loadstring(str)()
In either code, the contents of the variable str will be ran as a script, printing "hello world" to the output. |
|
|
| Report Abuse |
|
|
2tallhank
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 2075 |
|
|
| 25 May 2013 04:52 PM |
That makes sense.
What else could you do other than print "hello world"? |
|
|
| Report Abuse |
|
|
|
| 25 May 2013 04:57 PM |
Anything, it doesn't matter--just so long as it can be ran as executable code. The loadstring function actually returns two values, the first being the function, and the second being the error--if there is one. If the code ran successfully, the second returned value will be nil. Example:
local str = "hi" local func, err = loadstring(str) print(func, err)
> nil [string "hi"]:1: syntax error near < eof >
Or an example where it runs successfully:
local str = "print('hi')" local func, err = loadstring(str) print)(func, err)
> function: 0x1117b80 nil
|
|
|
| Report Abuse |
|
|
2tallhank
|
  |
| Joined: 11 Jun 2010 |
| Total Posts: 2075 |
|
|
| 25 May 2013 05:00 PM |
| Thank you for the information. |
|
|
| Report Abuse |
|
|
|
| 25 May 2013 05:01 PM |
No problem.
http://wiki.roblox.com/index.php/User:ElectricBlaze |
|
|
| Report Abuse |
|
|