Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Readers > More E-Book Readers > iRex > iRex Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 12-13-2008, 07:22 AM   #1
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Cool Lua: scripting for Iliad

Hi All,

Lua is a scripting language. And it's running on my Iliad right now! It's easy to learn (if you are used to programing), its interpreted (you don't have to compile anything), it's fast and small (the executable is 128K). Much smaller than perl, python or ruby; much easier and fun than shell scripts, awk, sed...

Lua is even cooler than it looks at first glance: it's easy to extend it (write functions in C, and call them from lua), or embed a lua interpreter in a C-program (it's used for scripting in game engines, camera's, ...)

The attached file contains the Lua binary with extensions for network stuff (luasocket) and XML parsing (luaexpat). This is enough to fetch files from Internet (ftp, http) and parse rss feeds. Unpacked it's less than 400K.

Is this cool or is it not? I can feel the karma

If you are interested to compile this stuff yourself: I keep notes on http://wiki.hpelbers.org/Other_stuff_for_the_Iliad. It's not complete or well maintained, but it might save some time...

Lua can be installed on your Iliad as follows:
Code:
tar xvfz lua_for_iliad.tar.gz
cd lua_for_iliad
cp -r * /usr/local
The executable will be in /usr/local/bin, which is included in PATH by default.

Happy scripting
Hansel

Links:PS: No warranty what so ever
PS2: I'm just playing with this: not going to maintain or document it
Attached Files
File Type: gz lua_for_iliad.tar.gz (126.3 KB, 491 views)

Last edited by hansel; 12-13-2008 at 03:04 PM. Reason: added link to tutorials and ref manual
hansel is offline   Reply With Quote
Old 12-13-2008, 07:57 AM   #2
ericshliao
Guru
ericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enoughericshliao will become famous soon enough
 
Posts: 976
Karma: 687
Join Date: Nov 2007
Device: Dell X51v; iLiad v2
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?
ericshliao is offline   Reply With Quote
Old 12-13-2008, 08:30 AM   #3
hansel
JSR FFD2
hansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheesehansel can extract oil from cheese
 
hansel's Avatar
 
Posts: 305
Karma: 1045
Join Date: Aug 2008
Location: Rotterdam, Netherlands, Europe, Sol 3
Device: iliad
Hi ericshliao,

Quote:
Originally Posted by ericshliao View Post
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 ;-)

Last edited by hansel; 12-15-2008 at 05:59 AM. Reason: correct version of example
hansel is offline   Reply With Quote
Old 12-14-2008, 07:51 PM   #4
Lemming
Member
Lemming began at the beginning.
 
Posts: 13
Karma: 10
Join Date: Nov 2008
Device: Various
This is really cool - Lua is a really interesting language, definitely not just for games. It seems like it would be a good fit for writing Iliad apps, for sure - lightweight, extensible, fast. Adobe Lightroom is about 70% Lua.

Cheers,
Colin
Lemming is offline   Reply With Quote
Reply

Tags
iliad, lua, scripting


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting with epub-meta averyml Calibre 20 11-17-2016 11:13 AM
DR800 Lua 5.1 MegaPackage for DR800 Iñigo iRex 25 10-05-2011 05:11 PM
DR800 ANN: RunDebug and Icon lua scripts Iñigo iRex 4 07-21-2010 08:35 AM
Possible scripting engine for Sigil Valloric Sigil 48 10-17-2009 10:58 AM
Any NetNewsWire Scripting Pros out there? adinb Sony Reader 0 02-25-2007 02:44 AM


All times are GMT -4. The time now is 10:33 PM.


MobileRead.com is a privately owned, operated and funded community.