Update main.lua
This commit is contained in:
parent
69c8b37854
commit
d62ad73ae7
1 changed files with 48 additions and 93 deletions
139
main.lua
139
main.lua
|
|
@ -1,110 +1,65 @@
|
||||||
-- it's like dancing on ice
|
local C = 0
|
||||||
local function class(factory,stuff)
|
local class_registry = {}
|
||||||
local meta = stuff
|
local function class()
|
||||||
for index,item in pairs(stuff) do
|
C = C + 1
|
||||||
meta["__"..index] = item
|
class_registry[C] = {}
|
||||||
|
return C
|
||||||
end
|
end
|
||||||
return setmetatable(meta,{
|
local link = function(a,c,v,b)
|
||||||
__call=function(this,...)
|
if not a[c] then a[c] = {} end
|
||||||
setmetatable(factory(...),meta)
|
if not b[-c] then b[-c] = {} end
|
||||||
|
a[c][b] = v
|
||||||
|
b[-c][a] = v
|
||||||
end
|
end
|
||||||
})
|
local classes = {}
|
||||||
|
for character in ("abcdefghijklmnopqrstuvwxyz "):gmatch(".") do
|
||||||
|
classes[character] = class()
|
||||||
end
|
end
|
||||||
local function iterate(thing)
|
classes.next = class()
|
||||||
local closure = pairs(thing)
|
classes.inp = class()
|
||||||
return function(...)
|
classes.out = class()
|
||||||
local index,item in closure(...)
|
local function l(a,c,v,b)
|
||||||
return item
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local c = class(function()
|
|
||||||
return {i = {}}
|
|
||||||
end)
|
|
||||||
|
|
||||||
local n = class(function(c,v,a,b)
|
|
||||||
local new = {c = c, v = v, a = a, b = b, s = {}}
|
|
||||||
table.insert(a.s,new)
|
|
||||||
table.insert(c.instances,new)
|
|
||||||
return new
|
|
||||||
end)
|
|
||||||
local I = 1
|
|
||||||
local n = function(c,...)
|
|
||||||
N(c,I,...)
|
|
||||||
end
|
|
||||||
|
|
||||||
c.cookie = c()
|
|
||||||
c.before = c()
|
|
||||||
c.after = c()
|
|
||||||
c.out = c()
|
|
||||||
c.in = c()
|
|
||||||
c.so = c()
|
|
||||||
c[";"] = c()
|
|
||||||
for i in string.byte("a"),string.byte("z") do c[string.char(i)] = c() end
|
|
||||||
do
|
|
||||||
-- !a; !b; !next(a,b) <- !before(b,a) -- if b is after a then a is before b
|
|
||||||
local a = n();
|
|
||||||
local b = n();
|
|
||||||
N(c.so,N(c.next,a,b),N(c.before,b,a))
|
|
||||||
end
|
|
||||||
|
|
||||||
local function s(r)
|
|
||||||
local objects = {r}
|
|
||||||
local time = 0
|
|
||||||
while true do
|
|
||||||
for o in iterate(objects) do
|
|
||||||
for similar in iterate(o.c.i) do
|
|
||||||
for _depends in iterate(similar.s) do
|
|
||||||
if _depends.c == c.so then
|
|
||||||
for linked in iterate(_depends.b.s) do
|
|
||||||
local fail = false
|
|
||||||
for depends in iterate(linked.s) do
|
|
||||||
if depends.c == c.so and depends.b == linked then
|
|
||||||
for instanced in iterate(o.s) do
|
|
||||||
if depends.c == instanced.c then
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
local function r(it)
|
||||||
end
|
for class,link in pairs(it) do
|
||||||
end
|
for to,value in pairs(link) do
|
||||||
if not fail then
|
r(to)
|
||||||
|
if class > 0 then
|
||||||
|
l(it,class,value,to)
|
||||||
|
else
|
||||||
|
l(to,-class,value,it)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
for linked in iterate(o.s) do
|
|
||||||
table.insert(objects,linked)
|
|
||||||
end
|
|
||||||
time = time + 1
|
|
||||||
if time > 100 then return end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local input = io.read()
|
local input = io.read()
|
||||||
local command,rest = input:match("%a*.+")
|
local command,param = input:match("([^%s]+)(.*)")
|
||||||
local previous = N(c())
|
local function say(author,text)
|
||||||
local function write(text,author)
|
local previous
|
||||||
for char in text:match(".") do
|
for character in text:gmatch(".") do
|
||||||
if author[char] then
|
if classes[character] then
|
||||||
local it = n(author[char])
|
local it = {}
|
||||||
N(c.in,it)
|
if previous then
|
||||||
N(c.after,previous,it)
|
link(previous,classes.next,I,it)
|
||||||
|
end
|
||||||
|
link(it,classes.inp,I,{})
|
||||||
|
link(it,classes[character],I,{})
|
||||||
|
previous = it
|
||||||
|
r(it)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
(({
|
(({
|
||||||
["in"] = function()
|
["inp"] = function(text)
|
||||||
write(rest,c.in)
|
say(classes.inp,text)
|
||||||
end,
|
end,
|
||||||
["out"] = function()
|
["out"] = function(text)
|
||||||
write(rest,c.out)
|
say(classes.out,text)
|
||||||
end,
|
end,
|
||||||
["cookie"] = function()
|
["exit"] = function()
|
||||||
write()
|
os.exit()
|
||||||
end,
|
end
|
||||||
})[command] or function() write(command..rest,c.in) end)()
|
})[command] or function(param) print("Unexpected command: '"..command.."' for '"..param.."''") end)(param)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue