259 posts
Posted 31 August 2013 - 05:18 PM
I would like to have some way that you could use a read() or similar input method and have a turtle use it like it was in the lua interpreter. I'm not using read() I'm actually using chat(message) from misc peripherals. I would like to be able to give this turtle commands like I was in lua.
1688 posts
Location
'MURICA
Posted 31 August 2013 - 05:24 PM
You can run lua commands using loadstring(). loadstring() returns a function, which you can call to then run the specified string.
local cmd = "print('Hello world!')"
local func = loadstring(cmd)
func() --> Hello world!
If you want to run a string without crashing, use pcall().
local ok, err = pcall(func)
if not ok then
print(err)
end
pcall() returns true or false, whether the function ran successfully or not. If ok is false, err is the error message.