Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
-- This file:
--   http://anggtwu.net/LUA/Actions1.lua.html
--   http://anggtwu.net/LUA/Actions1.lua
--          (find-angg "LUA/Actions1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- Based on: (find-angg "LUA/Verbatim1.lua")
--           (find-angg "LUA/Verbatim3.lua")
-- (defun a () (interactive) (find-angg "LUA/Actions1.lua"))

-- «.Actions»	(to "Actions")
-- «.Actions-tests»	(to "Actions-tests")



--     _        _   _                 
--    / \   ___| |_(_) ___  _ __  ___ 
--   / _ \ / __| __| |/ _ \| '_ \/ __|
--  / ___ \ (__| |_| | (_) | | | \__ \
-- /_/   \_\___|\__|_|\___/|_| |_|___/
--                                    
-- «Actions»  (to ".Actions")

Actions = Class {
  type  = "Actions",
  from  = function (oo) return Actions {oo=oo} end,
  __tostring = function (a) return mytostring(a) end,
  __index = {
    act1 = function (a, action, ...) 
        local _action = "_"..action
        if not a.oo[_action] then error("Unrecognized action: "..action) end
        a.oo[_action](a.oo,...)
        return a.oo
      end,
    act = function (a, str)
        for _,actionarg in ipairs(split(str)) do
	  local action,arg = actionarg:match("^([^:]+):?(.*)$")
          if arg then a:act1(action, arg) else a:act1(action) end
	end
	return a.oo
      end,
  },
}

Foo = Class {
  type    = "Foo",
  __tostring = function (foo) return mytostring(foo) end,
  __index = {
    act1 = function (foo, ...) return Actions.from(foo):act1(...) end,
    act  = function (foo, ...) return Actions.from(foo):act (...) end,
    _p      = function (foo)     foo.o = "("..foo.o..")" end,
    _pl     = function (foo,str) foo.o = "("..str..":"..foo.o..")" end,
    _format = function (foo,fmt) foo.o = format(fmt, foo.o) end,
  },
}



-- «Actions-tests»  (to ".Actions-tests")
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Actions1.lua"
foo = Foo {o="a"}
foo:_p()
foo:_pl("a")
= foo.o

foo = Foo {o="a"}
= foo
= foo:act1("p")

= Actions.from(foo)
= Actions.from(foo):act1("p")
= Actions.from(foo):act1("p")
= Actions.from(foo):act1("format", "[%s]")
= Actions.from(foo):act ("p p")
= Actions.from(foo):act ("pl:foo")
= Actions.from(foo):act ("aninvalidaction")

foo = Foo {o="a"}
= foo
= foo:act("p pl:a format:[%s]")


--]]



-- Local Variables:
-- coding:  utf-8-unix
-- End: