Skip to content

Instantly share code, notes, and snippets.

@8573
Created December 4, 2013 02:21
Show Gist options
  • Save 8573/7781220 to your computer and use it in GitHub Desktop.
Save 8573/7781220 to your computer and use it in GitHub Desktop.
Example Lua implementation of a “cat” program, for the education of Vultraz.
-- 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
@8573
Copy link
Author

8573 commented Dec 4, 2013

@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”.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment