-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.lua
112 lines (112 loc) · 2.19 KB
/
commands.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--handles commands
local cmds = {}
local commands = {}
cmds.cpu = dofile("wip/cpu.lua")
cmds.cpu.init()
cmds.find = dofile("wip/value.lua").find
cmds.commands = commands
cmds.addonsVar = {}
function commands.set(cpu,a,b)
cpu.setValue(a,cpu.getValue(b,cmds.find))
end
function commands.include(cpu,path,name)
local addon,setCore,appVars = dofile(path)
if setCore then
setCore(cmds)
end
if name then
for n,v in pairs(addon) do
commands[name.."."..n] = v
end
cmds.addonsVar[name] = appVars
else
for n,v in pairs(addon) do
commands[n] = v
end
for n,v in pairs(appVars) do
if not cmds[n] then
cmds[n] = v
end
end
end
end
function commands.label(cpu,name)
cpu.label(name,cpu.pos + 2)
end
function commands.define(cpu,name,value)
cpu.variables[name] = value or 0
end
--loads a whole dictonary
function commands.lib(cpu,dictonary,name)
local names = fs.list(dictonary)
local paths = {}
for i,v in ipairs(names) do
table.insert(paths,fs.combine(dictonary,v))
end
if name then
for i,v in ipairs(paths) do
commands.include(cmds.cpu,v,name.."."..names[i])
end
else
for i,v in ipairs(paths) do
commands.include(cmds.cpu,v)
end
end
end
--execute commands
function cmds.next()
return cmds.cpu.nextInst()
end
function cmds.execute(line)
if line == false then return true end
local tokens = {}
for match in line:gmatch("[^%s]+") do
table.insert(tokens,match)
end
local command = table.remove(tokens,1)
if commands[command] then
commands[command](cmds.cpu,unpack(tokens))
end
return {command,unpack(tokens)}
end
function cmds.tick()
return cmds.execute(cmds.next())
end
function cmds.flush(file)
if type(file) == "file" then
cmds.cpu.setBuffer(file.readAll())
file.close()
else
cmds.cpu.setBuffer(file)
end
end
--addons
function cmds.getVars(name)
return cmds.addonsVar[name]
end
function cmds.setVars(name,new)
cmds.addonsVar[name] = new
end
function cmds.getVar(addon,name)
return cmds.addonsVar[addon][name]
end
function cmds.setVar(addon,name,value)
cmds.addonsVar[addon][name] = value
end
--test
--[[
local file = fs.open("wip/test.wip","r")
local data = file.readAll():gsub("%\\","")
print("data:")
print(data)
print("main:")
cmds.flush(data)
file.close()
--]]
function cmds.run()
while not cmds.cpu.empty do
cmds.tick()
end
end
--cmds.run()
return cmds