93 posts
Posted 19 July 2013 - 11:51 AM
I am not sure if this is a bug, but when I create a file with a function called "shell" EVERY program, rom or not, that uses the shell api breaks. It will error out on the first line that calls shell.(Some function).
It's not annoying, but I just wanted to know if it is a bug or it's just me screwing with CraftOS and found a way to break it. Thanks.
1619 posts
Posted 19 July 2013 - 12:01 PM
It's you. :P/>
2447 posts
Posted 19 July 2013 - 12:45 PM
You're replacing the shell table with a function. What did you expect to happen?
This is why in your own code you should do local function shell().
2217 posts
Location
3232235883
Posted 19 July 2013 - 12:47 PM
or not use shell at all
;_; what if you need to shell.run something
(i guess you could just use dofile, but that dosent automatically search rom or add to the shell stack)
3790 posts
Location
Lincoln, Nebraska
Posted 19 July 2013 - 12:48 PM
Wait what? You expect an api to work after you overwrote it?
I don't understand your logic…
8543 posts
Posted 19 July 2013 - 02:15 PM
Moved to Ask a Pro.
159 posts
Location
A Chair
Posted 19 July 2013 - 08:09 PM
Change the name of your function. eg. Shell() is different to shell()
The reason you broke everything is because Lua is "re-programmable" you can assign a default function or program to a random varible, fx. a = os.reboot
you could then write a() and the computer would reboot.
another example would be "oldpull = os.pullEvent" and then "os.pullEvent = os.pullEventRaw" – the quick CTRL + T disable system ( which stores the function for later restoration with "os.pullEvent = oldpull" ).
So you can damage the shell and any other functions by creating the wrong type of function names. ( try to avoid re-using the shell and default function names ).
93 posts
Posted 27 July 2013 - 06:21 PM
Thank you all. I know it kind of sounded stupid, but I didn't know that lua was re-programmable. I always thought that when you did something like "os.pullEvent = os.pullEventRaw", you were just assigning a variable to it and tricking the language. I see my issue now. Thank you!
P.S. I just wanted advice, not hate comments.
159 posts
Location
A Chair
Posted 28 July 2013 - 09:42 AM
you can make one function call a bunch of api functions… It's basically a language that can re-write itself. eg, function Up() turtle.up print("Turtle moving up") end
That would make a function Up() that called the function up() but from within the API turtle. (the API system is basically a bunch of functions that are gathered in a single program)
so if you use a bunch of Functions in sevveral programs… Instead of writing the functions in every program, we make a API program that contains the functions. You basically load the API at the startup of the program and then call the functions with the API_name.function_name() eg turtle.up() would call the turtle API (program) and run the function up() from inside the program…
What occured when you created the shell() function was that you overwrote the shell.function() api. ( as it tried to call shell() then find a function inside of the shell() function ) which errors as the shell function contains no sub functions.
Btw, I hope my post helped you understand the error before. It was meant in a helpfull way to help you understand the way lua and CC works.