benanders / LuaIDE

An in-game IDE for ComputerCraft
MIT License
43 stars 10 forks source link

unable to run from a program? #43

Closed DarkenedEvil closed 10 years ago

DarkenedEvil commented 10 years ago

When I try to run luaide through my OS(DarkOS) it gives an error "luaide:36: attempt to index ? (a nil value)".

How to replicate: 1) Create a while loop and wait for a mouse_click on a certain spot 2) Click that spot and once clicked run luaide with os.run({}, "luaide") and shell.run("luaide") 3) Get error!

I tried to run it out side of the OS by typing in luaide and it ran fine. I then opened a new file and had it run shell.run("luaide") just that and it worked.

Thanks in advanced.

benanders commented 10 years ago

That would be because LuaIDE uses the shell library, and running it using os.run({}, "luaide") effectively removes that shell library (basically because the shell library is stored in the top layer of the environment, which you override using the {} in the os.run, meaning it's destroyed. Using os.run({["shell"] = shell}, "luaide") should work I think). Use shell.run instead, because it preserves the top layer of the environment (including the shell library). Or, if you REALLY must use os.run, try os.run({["shell"] = shell}, "luaide").

DarkenedEvil commented 10 years ago

It still does not work. Also in the OP I said that I tried both shell.run and os.run. I don't know why this is like this not even your recommendation worked.

benanders commented 10 years ago

After testing it, both my suggestion of os.run({["shell"] = shell}, "luaide") and shell.run work for me. os.run({}, "luaide") didn't, giving me the same error you said in the OP. Line 36 contains a shell.getRunningProgram(), so what I mentioned is the problem. Not sure what you've done differently.

DarkenedEvil commented 10 years ago

I have found a way around this, but it does involve some slight editing of your code. Do I have permission to change the code around a bit then release it in my next version of my OS? Of Course you will have credit in the OS and on the topic on the CC forums.

benanders commented 10 years ago

Sure.