|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/Basic1.lua.html
-- http://anggtwu.net/LUA/Basic1.lua
-- (find-angg "LUA/Basic1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- (defun e () (interactive) (find-angg "LUA/Basic1.lua"))
BLine = Class {
type = "BLine",
__tostring = function (bl) return format("%4d %s", bl[1], bl[2]) end,
__index = {
},
}
BLines = Class {
type = "BLines",
__tostring = function (bls) return mapconcat(tostring, bls, "\n") end,
__index = {
find = function (bls, n)
for i=1,#bls do if bls[i][1] >= n then return i end end
end,
set = function (bls, n, body)
local i = bls:find(n)
if i and bls[i][1] == n then table.remove(bls, i) end
if body then table.insert(bls, i or #bls+1, BLine {n,body}) end
return bls
end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Basic1.lua"
= BLine {10, "print 42"}
bls = BLines {
BLine {10, "print 42"},
BLine {20, "n=n+1"},
BLine {30, "print n"},
}
= bls
= bls:find(15)
= bls:find(20)
= bls:find(50)
= bls:set(20)
= bls:set(20, "foo")
= bls:set(30, "bar")
= bls:set(40, "plic")
--]]
-- Local Variables:
-- coding: utf-8-unix
-- End: