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

Is There A Function Like Shell.run() for Normal Lua(without any cc apis)?

Started by Dusty_Rebel, 04 January 2013 - 05:37 AM
Dusty_Rebel #1
Posted 04 January 2013 - 06:37 AM
Is There A Function Like Shell.run() for Normal Lua(without any cc apis)? I Am Using A iOS Application Titled: "Touch Lua" and i know how to do most things on it except making it do like a shell.run() type of function?


P.S. I Have No Way To Access lua.org





Regards'
Dusty_rebel
Lyqyd #2
Posted 04 January 2013 - 06:42 AM
Try loadstring. Returns a function if the string loaded successfully, or (I believe) nil and an error message if it didn't.
Dusty_Rebel #3
Posted 04 January 2013 - 06:53 AM
If I May Ask How Do I Loadstring? I really suck at (non-cc/roblox) Lua
Dusty_Rebel #4
Posted 04 January 2013 - 06:56 AM
P.S. im using this for a quiz script i made on my phone so that if you get incorrect it restarts the program
Bubba #5
Posted 04 January 2013 - 07:11 AM

local f = io.open("program", "r")
local content = f:read("*all")
f:close()
local runCode = loadstring(content)
runCode()

Although the above code should work, I don't really see a need to use loadstring in this case. Just encapsulate your quiz code in a function, and then use simple if/else statements to decide whether to restart or continue.
Kingdaro #6
Posted 04 January 2013 - 07:16 AM
Isn't there a loadfile() and dofile() in lua?
Bubba #7
Posted 04 January 2013 - 07:20 AM
Isn't there a loadfile() and dofile() in lua?

Actually yes there is. It's usage is dofile([progname]). That would be a simpler way to go about it, but I still think that an entire program restart is unnecessary.
Lyqyd #8
Posted 04 January 2013 - 07:33 AM
And probably fills the stack. This should be accomplished with the use of a (rather elementary) loop, nothing more.
Dusty_Rebel #9
Posted 04 January 2013 - 07:55 AM
But i also want to be able to run a differnet program from one program for instance a main script that lets you say "quiz" and it bring you to the quiz
so can anyone help me with that?
Dusty_Rebel #10
Posted 04 January 2013 - 07:57 AM
and when i do dofile("Quiz") it says ERROR: unknown directory/file
Lyqyd #11
Posted 04 January 2013 - 08:42 AM
Then you obviously have the wrong path to the file. Try looking through the documentation to see what the path should look like.
Dusty_Rebel #12
Posted 04 January 2013 - 08:44 AM
the documentation? im usin an iOS applictaion…
Lyqyd #13
Posted 04 January 2013 - 08:51 AM
Yes, the documentation for whatever app you're using. The app, by the way, that none of us have any reason to have any experience with, or know anything about, and that isn't ComputerCraft. So don't expect us to be able to answer questions about it like we can about ComputerCraft.
GravityScore #14
Posted 04 January 2013 - 08:55 AM
In ComputerCraft, whenever you specify a file path, it is taken from the root directory of the computer you're using. Since you're not using ComptuerCraft, the file path you'll have to specify is the full path to the file you want to run using dofile (or to open using the io API - the FS api doesn't exist outside of ComptuerCraft). Full paths are taken from the root of your computer, like so:

Windows (not sure about this full path):

C:\Users\yourusernamehere\My Documents\Lua\test.lua

Mac:

/Users/yourusernamehere/Documents/Lua/test.lua
or
~/Documents/Lua/test.lua

The error unknown file or directory means that Lua could not find the file - it doesn't exist. That's because you didn't specify the full path to it.
Lyqyd #15
Posted 04 January 2013 - 08:59 AM
Though, you might try ./filename, since that can often be used for relative paths.
Dusty_Rebel #16
Posted 04 January 2013 - 09:56 AM
Ok I'll try that


EDIT: /Quiz Still doesnt work :/
Edited on 04 January 2013 - 09:13 AM
Dusty_Rebel #17
Posted 04 January 2013 - 10:18 AM
i checked the documentation it says nothing about path directories…
Orwell #18
Posted 04 January 2013 - 10:22 AM
Ok I'll try that


EDIT: /Quiz Still doesnt work :/
Not /Quiz, ./Quiz . With a dot in front. Is the quiz file in the same directory as the main file?
Dusty_Rebel #19
Posted 04 January 2013 - 10:28 AM
Oh ./Quiz ok and I don't know…


EDIT: nope still don't work :/
Dusty_Rebel #20
Posted 04 January 2013 - 10:38 AM
I think I'm gonna use iExplorer…

EDIT: I tried documents/quiz and it just didn't work I saw that's where the directory is and it didn't work :/
Dusty_Rebel #21
Posted 04 January 2013 - 10:49 AM
I way insert some cc Apis while im in iExplorer