Hi ericshliao,
Quote:
Originally Posted by ericshliao
The Lua website declares that it's some script for game (if I read it correctly). Do we have some example to run on iLiad?
|
No useful examples yet... But I was able to fetch a web page and read the Iliad networkprofiles (XML) with just a few lines of code...
Lua is not only for games: it's a full blown general purpose language.
You can do anything you want with files, numbers, regular expressions, sockets, whatever. It's used in games because it's small, fast, and easy to embed. String handling is much easier than in C. You don't have to compile: you can test on your PC, and run on your Iliad by just copying the file. Plus it can do what you normally do with shell scripts...
I'm still learning Lua (used to C, C++ and Ruby), but I like what I see!
Here's a small example with file io and (cryptic

) string stuff: you can save it as hexdump.lua
Code:
local index = 0 -- offset in file
local block = 16 -- bytes on a line
-- process file if given, else read from stdin
if arg[1] then
io.input(arg[1])
end
while true do
local bytes = io.read(block)
if not bytes then break end
io.write(string.format("%04X: ", index)) -- byte counter
for b in string.gfind(bytes, ".") do
io.write(string.format("%02X ", string.byte(b))) -- hex values
end
io.write(string.rep(" ", block - string.len(bytes) + 1))
io.write(string.gsub(bytes, "%c", "."), "\n") -- ascii values
index = index+block
end
You can call is as:
Code:
echo "hello" | lua hexdump.lua # read from standard input
lua hexdump.lua /etc/passwd # read a file and dump it
lua hexdump.lua </etc/passwd # use file content as input
Google around a bit and be happy ;-)