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

[Lua][Question]Loading a file into a function

Started by gsprati, 22 October 2012 - 04:29 PM
gsprati #1
Posted 22 October 2012 - 06:29 PM
How can I load files into functions that are not in a folder? I used this code:

print(type(loadfile("someExistingFile")))
print(type(loadfile("rom/startup")))
Output:

nil
function
Lyqyd #2
Posted 22 October 2012 - 09:02 PM
You need a valid Lua script in the file for loadstring to work.
ChunLing #3
Posted 22 October 2012 - 09:26 PM
More precisely, it is working by returning a nil as the first value. If you do "tempfunc,errmssg = loadfile("someExistingFile")", and then print errmssg if tempfunc is nil, you'll get to see what lua doesn't like about your file.
gsprati #4
Posted 23 October 2012 - 04:13 PM
Thanks for the help, but now it somehow worked without changing any code.