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

Load code from a file

Started by GreenGene, 29 October 2015 - 01:03 AM
GreenGene #1
Posted 29 October 2015 - 02:03 AM
Hello! I would like to know how to load code from a file without an api like os.loadApi() or shell.run() tnx ~GreenGene
GreenGene #2
Posted 29 October 2015 - 02:09 AM
I found that loadstring() works, thank you for viewing this topic though ;)/>
Creator #3
Posted 29 October 2015 - 05:21 AM
or dofile("path")
Lupus590 #4
Posted 29 October 2015 - 07:38 AM
dofile is better I think
valithor #5
Posted 29 October 2015 - 11:38 AM
Dofile uses loadstring, so it really is up to preference. Since he said load code from a file out of the two loadstring is definitely the better direct solution.

However, there is a function defined in the bios that will save you a little time, if you only want to load the file as a function but not have it automatically executed like if you were to use dofile. loadfile just loads the file at the given path, and iirc you can pass an environment as the second arg which is used when loadstringing the file.