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

Load a files code and run it in a different program

Started by Varscott11, 28 August 2016 - 12:02 AM
Varscott11 #1
Posted 28 August 2016 - 02:02 AM
This has stumped me for a long time now. I have two files:

file1:"unet"
file2:"unetclientdata/libraries/rnetconfigx12"

I need the unet program to load the entire file, rnetconfigx12, and run it as if the code for file2 was part of file1.

Sorry if this is too much, but I also need them to be compatible with each other. As in file 2 can call functions from file 1 and vise versa.

Any help is appreciated!
KingofGamesYami #2
Posted 28 August 2016 - 02:37 AM
This PIL Chapter may be of use to you.
Varscott11 #3
Posted 28 August 2016 - 02:56 AM
I took a look at the PIL, and had some trouble with it. But what I have gathered is that I might need to use loadfile to get the code over to file1? correct me if i'm wrong
KingofGamesYami #4
Posted 28 August 2016 - 03:05 AM
loadfile would be one of the ways, yes.
Varscott11 #5
Posted 28 August 2016 - 03:09 AM
If I do loadfile, will that allow for one file to call functions of the other?
Varscott11 #6
Posted 28 August 2016 - 04:49 PM
I have tried loadfile, and the other script runs like it should. Sort of. The two scripts however don't communicate with each other, and I cannot call functions that are stored in the other file correctly. Any ideas?
Bomb Bloke #7
Posted 29 August 2016 - 05:45 AM
As in file 2 can call functions from file 1 and vise versa.

This sounds ominous - there's seldom good reason to go both ways like that. Are you planning on making recursive calls? If so (and if you don't understand what they are, assume "yes"), are you aware of the potential pitfalls?

If you really "must" store your code across multiple files, then your main problem boils down to scope. You can share the global environment between your separately loaded files, but I'm not aware of any way to do this with values declared local to the individual files.

I'm strongly suspecting that you'd be better off looking into CC's API system.
Varscott11 #8
Posted 29 August 2016 - 04:24 PM
I have taken into account the api system and have even employed it once in the code. However I still was not able to call functions properly and it came up with an error that said the function I was asking for was a nil. I've looked over both scripts and they are both pretty close to devoid of bugs, as I debug as I go. I really don't know what I'm doing wrong. It might be a bug in my code, which I could sort out, but I need to make sure that what I do, can atleast call functions from the other script.

P.S Thanks for the help so far. :)/>
Bomb Bloke #9
Posted 30 August 2016 - 06:47 AM
Odds are someone could point out the problems to you if you were to display your code.

http://www.pastebin.com
Lupus590 #10
Posted 30 August 2016 - 09:06 AM
You may want to have a look at Howl: http://www.computercraft.info/forums2/index.php?/topic/21254-howl-lua-build-system/