loadfile
From ComputerCraft
Jump to navigation
Jump to search
loadfile Function | |
---|---|
Syntax loadfile() | |
Returns | string |
API | Base globals |
Source | CC:Tweaked (source) |
Takes a filename and will return a function if it's succesful. If it's not, it will return nil and a error message.
Note: The format is loadfile( filename, env ) is also accepted, for older versions, but shouldn't be used.
|
|||
Code | function executeFile( filename, ... )
local ok, err = loadfile( filename )
print( "Running "..filename )
if ok then
return ok( ... )
else
printError( err )
end
end
executeFile( "doesnotexist.lua" )
executeFile( "rom/programs/id.lua" )
|
||
Output | Running doesnotexist.lua
File not found
Running rom/programs/id.lua
This is computer #1
|
Retrieved from "https://wiki.computercraft.cc/index.php?title=Loadfile&oldid=5800"