7 posts
Posted 22 May 2013 - 04:35 AM
Hello.
This is the idea I have, but since i created this topic you can tell it isn't working.
startup
shell.run("test","hello world")
test
args={...}
if args[1]=="hello world" then
return "hello user"
end
So is it possible to run a file and make the file return something except true?
671 posts
Location
That place over there. Y'know. The one where I am.
Posted 22 May 2013 - 04:46 AM
Not like that no :(/> sorry!
7 posts
Posted 22 May 2013 - 05:08 AM
I would like to do it because my files are getting too big and it's hard to keep an overview so I would like to seperate the big functions to their own files.
Is there another way to do that?
992 posts
Posted 22 May 2013 - 05:43 AM
shell.run or os.run won't do this but this will
[EDIT] added better handling of errors in program
local function run(path,...)
if fs.exists(path) and not fs.isDir(path) then
file = fs.open(path,"r")
if file then
local sFunk = file.readAll()
file.close()
local prog,err = loadstring(sFunk)
if prog then
return prog(...)
else
error(err)
end
else
error("Unable to open file")
end
else
error("File not found")
end
end
print(run("prog"))
7 posts
Posted 22 May 2013 - 06:04 AM
Omg, you really are a Lua god!
Thank you so much the script :)/>
1688 posts
Location
'MURICA
Posted 22 May 2013 - 06:09 AM
The dofile function returns results from scripts.
-- test
return 'bacon'
-- startup
local str = dofile('test')
print(str) --> bacon
992 posts
Posted 22 May 2013 - 06:15 AM
The dofile function returns results from scripts.
– snip
and this is why I wanted "lua amature" not "lua god"
7 posts
Posted 22 May 2013 - 06:51 AM
Wow.. I think I'll take dofile then.
Thank you for helping me, all of you :)/>
Edit: how do I parse arguments with dofile?
1688 posts
Location
'MURICA
Posted 22 May 2013 - 08:11 AM
…Huh. It seems as though you can't pass arguments using dofile, haha.
8543 posts
Posted 22 May 2013 - 01:11 PM
This seems like you should be using an API instead, to be honest.