40 posts
Location
Poland
Posted 27 July 2012 - 07:40 PM
Hello, I'm back.
Recently I had to deal with an interesting Lua error. When I tried to load a text file with size of 2 MB, an error occurred at line 32, "
Too long without yielding". I know that this mainly occurs in loops, so I checked the "edit" program, and yes, line 32 is a part of loop.
Since I'm not an idiot, I decided to Google it. Surprisingly, 3/4 of results were related to ComputerCraft.
Finally, I used my old Lua interpreter I wrote in C# using
LuaInterface a month ago. I created a simple "while true do end" script and started interpreting. Even though I had to exit the program using Task Manager,
NO ERROR OCCURRED! How is it possible?!
Now the question:
What the hell is this? An error that only occurs in CC, is undocumented and nobody fixed it until today. I guess it's another proof that Dan is a hopeless programmer, srs
992 posts
Posted 27 July 2012 - 07:46 PM
dont dis dan200
this is a idiot proofing measure mainly used for servers.
If a user could create hundreds of PC's with a loop running servers would crash this terminates that loop if repeated too many times.
2447 posts
Posted 27 July 2012 - 07:50 PM
Or maybe it's just proof that you're an idiot. If you took the time to learn how ComputerCraft works, you would see that the reason it has limits on how long code can run (and most Lua sandboxes do!) is so that other computers in the world can run. Lua isn't threaded - so coroutines are extensively used.
Lua on your PC isn't sandboxed (it has no need to be), which is why this error doesn't occur. Coroutines being used this way is actually a really clever way to get around Lua not being threaded.
If you, almighty l33t programmer can come up with a better solution, I would LOVE to hear it.
40 posts
Location
Poland
Posted 27 July 2012 - 07:55 PM
If a user could create hundreds of PC's with a loop running servers would crash this terminates that loop if repeated too many times.
That's what plugins are meant to do. Preventing users from doing such things. I'm 99,999% sure that this isn't any kind of protection.
So, people, you are saying that error occurring when Edit tries to open a normal text file is meant to be there, even though a standard Notepad can do this and even though the code is perfectly safe and ok?
@EDIT
Lua isn't threaded - so coroutines are extensively used.
But Java is.
And that's pretty much why my interpreter doesn't almost crash when running such scripts (since C# is threaded, too).
Edited on 27 July 2012 - 06:06 PM
2447 posts
Posted 27 July 2012 - 08:03 PM
If a user could create hundreds of PC's with a loop running servers would crash this terminates that loop if repeated too many times.
That's what plugins are meant to do. Preventing users from doing such things. I'm 99,999% sure that this isn't any kind of protection.
So, people, you are saying that error occurring when Edit tries to open a normal text file is meant to be there, even though a standard Notepad can do this and even though the code is perfectly safe and ok?
You are incorrect. This IS a form of protection which will be improved next version - but your error message will still occur. I will look into altering the edit program so it will no longer cause this problem - but it wasn't designed to handle 2MB text files and I can't even think of a reason where that would be useful inside CC.
Edit:
@EDIT
Lua isn't threaded - so coroutines are extensively used.
But Java is.
And that's pretty much why my interpreter doesn't almost crash when running such scripts (since C# is threaded, too).
This interpreter doesn't crash either. It is an
intentional limit. It is called a
sandbox. And if you really think multiple instances of Lua (which by the way, isn't possible with LuaJ) would magically make this better, you're mistaken.
40 posts
Location
Poland
Posted 27 July 2012 - 08:21 PM
You are incorrect. This IS a form of protection which will be improved next version - but your error message will still occur.
I didn't say I'm 100% sure that this is not a protection, kekeke. Also, I really look forward to the improvement.
Handling 2MB files would be useful while reading logs or even interpreting long scripts, lol.
Well, since this is a protection and cannot be removed, why not make the io.read() and similar functions less CPU-eating, for example, by creating them in Java and then just declaring them as variables in Lua environment?
2447 posts
Posted 27 July 2012 - 08:29 PM
Your suggestion regarding IO is exactly what happens (they bounce to the FS library which is implemented in Java, which calls native Java functions). The main issue is that the thread isn't yielding (which could be easily worked around).
2217 posts
Location
3232235883
Posted 27 July 2012 - 08:35 PM
I created a simple "while true do end" script and started interpreting. Even though I had to exit the program using Task Manager
sorry um, you had to exit it with task manager because it wasnt repsonding
thats what will happen to mc if you try to do that without the securety measure
40 posts
Location
Poland
Posted 27 July 2012 - 08:39 PM
OK. ComputerCraft is a sandbox. I understood.
My dreams will never come true.
However, I still think that the protection could at least be turned off, by server administrator in multiplayer and in CC configuration in singleplayer.
2447 posts
Posted 27 July 2012 - 08:43 PM
No. Turning off this protection would be suicide in multiplayer and in advisable in single player (without this protection you could have a completely bricked computer and lag your minecraft to heck). It is easy to code round - which is what I'll try and do to the built in editor before the release or CC 1.4.