This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
HurricaneCoder's profile picture

Coding explanation

Started by HurricaneCoder, 27 June 2013 - 05:23 PM
HurricaneCoder #1
Posted 27 June 2013 - 07:23 PM
Ok I saw direwolf20 mining turtle code and I do not know how he convert a string into a executable like of code. So I did a test and found out where it was coming from. The problem is I do not know what it is. So can someone please explain to me this:

function test()
print("test1')
end
func = loadstring("test".."(...)") 
setfenv(func,getfenv())
func()

Also can you explain to me what does the three period inside the bracket mean. I know that in a table it act as a variable for user to define.
Bubba #2
Posted 28 June 2013 - 01:29 AM
loadstring is essentially just a function that runs a piece of lua code that you give it in string form. So for example, If I downloaded some Lua code from a website and wanted to use it, I could just put it into the loadstring function and it would run.

The three dots indicate that the function is taking a variable number of arguments. A good explanation of it can be found here.