Jump to content




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

lua

  • You cannot reply to this topic
20 replies to this topic

#1 Dusty_Rebel

  • Members
  • 57 posts

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

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#3 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 06:53 AM

If I May Ask How Do I Loadstring? I really suck at (non-cc/roblox) Lua

#4 Dusty_Rebel

  • Members
  • 57 posts

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

#5 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

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.

#6 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 04 January 2013 - 07:16 AM

Isn't there a loadfile() and dofile() in lua?

#7 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 04 January 2013 - 07:20 AM

View PostKingdaro, on 04 January 2013 - 07:16 AM, said:

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.

#8 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#9 Dusty_Rebel

  • Members
  • 57 posts

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?

#10 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 07:57 AM

and when i do dofile("Quiz") it says ERROR: unknown directory/file

#11 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#12 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 08:44 AM

the documentation? im usin an iOS applictaion...

#13 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#14 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

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.

#15 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 04 January 2013 - 08:59 AM

Though, you might try ./filename, since that can often be used for relative paths.

#16 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 09:56 AM

Ok I'll try that


EDIT: /Quiz Still doesnt work :/

Edited by Dusty_Rebel, 04 January 2013 - 10:13 AM.


#17 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 10:18 AM

i checked the documentation it says nothing about path directories...

#18 Orwell

    Self-Destructive

  • Members
  • 1,091 posts

Posted 04 January 2013 - 10:22 AM

View PostDusty_Rebel, on 04 January 2013 - 09:56 AM, said:

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?

#19 Dusty_Rebel

  • Members
  • 57 posts

Posted 04 January 2013 - 10:28 AM

Oh ./Quiz ok and I don't know...


EDIT: nope still don't work :/

#20 Dusty_Rebel

  • Members
  • 57 posts

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 :/





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users