Jump to content




Little question to shell.run()


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

#1 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 20 May 2013 - 04:54 AM

I heared that, if you have a program (for example: test) and in this program are some lines of code. at the end you restart it with shell.run('test').

Why is this "bad"?

#2 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 20 May 2013 - 05:04 AM

Well I guess the easiest way for me to answer is to tell you to run this program and see what happens

program name: tester
shell.run('tester')

yep thats right, stackoverflow. using shell.run at the end of your program to loop your program is recursion.

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 20 May 2013 - 05:05 AM

So in other words, it's the same as doing this:
function toaster()
  toaster()
end


#4 SuicidalSTDz

    Permutator of Strings

  • Members
  • 1,308 posts
  • LocationPennsylvania

Posted 20 May 2013 - 06:34 AM

Reason: The stack in Lua is like a pile of clean dishes. Too many dishes and the stack crashes down. If a function yields however, it will be taken off the stack. Guess what, using recursion (in most cases) does not yield. So just don't use it if the situation you are using it in does not need it.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users