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

Why doesn't CC have the require function and the lua package system?

Started by ElvishJerricco, 04 June 2013 - 10:52 PM
ElvishJerricco #1
Posted 05 June 2013 - 12:52 AM
I can probably program my own implementation of it by changing loadfile but I'm curious why it's not in the lua vm. Can it be added?

EDIT: After tinkering and playing with the idea, it turns out to be rather difficult to do with pure lua because of how function environments are changed.
Lyqyd #2
Posted 05 June 2013 - 01:09 AM
I'm not sure I can speak as to why it doesn't use that model, but the API loading/unloading that it does use works well. What can you do with require that you cannot with the API loading?
Kingdaro #3
Posted 05 June 2013 - 01:38 AM
Correct me if I'm wrong, but dofile() is pretty much require() but with a different path naming system, e.g. dofile('folder/script.lua') would be require('folder.script'), so require isn't really needed. The API loading and unloading system is pretty much a remake of the module system too.
Cloudy #4
Posted 05 June 2013 - 07:46 AM
Basically, it would have broken out of the sandbox in a big way. That is why it isn't enabled. require was really dangerous - it even allowed you to reload the LuaJ IO library. Full access to whatever Java can access on your system, anyone? ;)/>
theoriginalbit #5
Posted 05 June 2013 - 07:49 AM
Basically, it would have broken out of the sandbox in a big way. That is why it isn't enabled. require was really dangerous - it even allowed you to reload the LuaJ IO library.
In no way saying you should add it, but could you not have just overrode it with a `safe` version like you did with other functions?

Full access to whatever Java can access on your system, anyone? ;)/>
/sarcasm Yes please :P/>
ElvishJerricco #6
Posted 05 June 2013 - 04:56 PM
I'm not sure I can speak as to why it doesn't use that model, but the API loading/unloading that it does use works well. What can you do with require that you cannot with the API loading?

Well a lot of lua libraries use the module paradigm so it would allow us to use lots more projects outside CC.

Basically, it would have broken out of the sandbox in a big way. That is why it isn't enabled. require was really dangerous - it even allowed you to reload the LuaJ IO library. Full access to whatever Java can access on your system, anyone? ;)/>/>

That makes sense. Good reason!