#

# Copyright (c) 2007, Damon Anton Permezel.  All rights reserved.

#


Some Lua scripts that may be of interest to VoodooPad users.


These are currently quite raw --- I have only been playing with this for about a week now.


I keep these in ~/lua, and typically put text in a VP page to modify the search path so that they are loaded on demand.


For me, it looks like:


    package.path = package.path .. ';/Users/dap/lua/?.lua'


1. voodoo.lua


This was intended to be a common 'pull everything I typically need' file.  Not sure yet what that means to me.  It might go away.


2. dump.lua


A data dumper.  I tend to use it a bit to look at the various tables &c.  Typical use is:


    package.path = package.path .. ';/Users/dap/lua/?.lua'

    require'dump'


    t={hi='there'}

    dump(t)


3. OO.lua


Working on a simple OO, single inheritance framework for my Lua programming.  Got some ideas from various places on the net, but basically all the weirdness you can blame me for.


See some of the following for examples of usage.


4. PageIO.lua


Sorry for the mess.  This took a lot of head banging.  Mainly because I was new to Lua, new to Voodoopad, and new to Objective-C, and all the weirdness that that entails.  I intend this to be the basis for a lot of the code I write as plugins for VoodooPad.  I will be revising it and adding to it.  Currently, it has just sufficient functionality for my HanoiPageIO.  See below.


5. Hanoi.lua


Towers of Hanoi base class.  Usage:


       package.path = package.path .. ';/Users/dap/lua/?.lua'

       Hanoi = require"Hanoi" -- load the class definition


       hanoi = Hanoi:new{nRings = 5}

       hanoi:run()


6. ScratchIO.lua


A sub-class of PageIO that uses a '*scratch*' page for I/O.  It is useful to keep the scratch page open in another window, and have a page with Lua script in another window, and then execite the scripts, directing output to scratch.


Usage:

package.path = package.path .. ';/Users/dap/lua/?.lua'

p=require("ScratchIO"):new {}


p:out('Hello world @ %s', os.date('%Y-%m %A %T'))


7. HanoiScratch.lua


A subclass of Hanoi that uses the scratch for output.


Usage:

       package.path = package.path .. ';/Users/dap/lua/?.lua'


       require'HanoiScratch':new { nRings = 5 } :run()


8. HanoiPageIO.lua


Derived class.  Performs the Towers of Hanoi, but uses the PageIO to perform I/O directly to a VoodooPad page.


   Usage:

   (ensure that your window is large enough first)


       package.path = package.path .. ';/Users/dap/lua/?.lua'

       Hanoi = require"HanoiPageIO" -- load the class definition


       hanoi = Hanoi:new{nRings = 5}

       hanoi:run()


One problem is that one the script is running, it cannot be interrupted.


9. HanoiPageIO_async.lua


It occurred to me that the rings could move asynchronously, so long as they obeyed the rules (don't occupy the same space, etc).  Lua has coroutines. I have time.....  This really is spiffy.  The code is a bit of a mess until I clean it up.....


Usage:


package.path = package.path .. ';/Users/dap/lua/?.lua'


require'HanoiPageIO_async':new{nRings=6}:run()


I have not figured out if I can control the window size (Gus?) so you will have to size the windows correctly....


WARNING WARNING WARNING WARNING WARNING WARNING WARNING


It works OK for me.  Use at your own risk.  Not tested on animals.


Enjoy!