Created
December 4, 2013 02:21
-
-
Save 8573/7781220 to your computer and use it in GitHub Desktop.
Example Lua implementation of a “cat” program, for the education of Vultraz.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Usage: lua cat.lua file1 file2 file3 ... fileN | |
-- Writes the concatenation of all the files to the standard output stream. | |
for _, filename in ipairs(arg) do | |
local file, err = io.open(filename, 'rb') | |
if file then | |
io.write(file:read '*a') | |
else | |
error(filename .. ": " .. err) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Vultraz: Please do try to understand this rather than just copying it without knowing what it does.
If you would ask “but what do these io functions do?”, read http://www.lua.org/manual/5.2/manual.html#6.8. (I assume you don’t already know how the
io
library works, given that Wesnoth doesn’t allow its use.)If you would ask “but where do I get lua for windows?”, try instead searching Google for “windows lua”.