Module:IC10: Difference between revisions
From Stationeers Wiki
More actions
m tweaking colours |
m tweaking colours |
||
| Line 56: | Line 56: | ||
-- devices d0–d5 plus d? | -- devices d0–d5 plus d? | ||
line = string.gsub(line, "%f[%w](d([0-5]|%?))%f[%W]", | line = string.gsub(line, "%f[%w](d([0-5]|%?))%f[%W]", | ||
'<span style="color:# | '<span style="color:#00ff00;">%1</span>') | ||
-- numbers hex | -- numbers hex | ||
Revision as of 07:36, 20 February 2026
local p = {}
-- List of IC10 opcodes (all strings) local opcodes = {
"alias","define","hcf","yield", "abs","add","ceil","div","pow","exp","floor","log","max","min","mod","move","mul","rand","round","sqrt","sub","trunc","lerp", "acos","asin","atan","atan2","cos","sin","tan", "clr","clrd","get","getd","peek","poke","pop","push","put","putd", "l","lr","ls","s","ss","rmap", "lb","lbn","lbns","lbs","sb","sbn","sbs", "and","nor","not","or","sla","sll","sra","srl","xor","ext","ins", "select","sdns","sdse","sap","sapz","seq","seqz","sge","sgez","sgt","sgtz","sle","slez","slt","sltz","sna","snan","snanz","snaz","sne","snez", "j","jal","jr", "bdnvl","bdnvs","bdns","bdnsal","bdse","bdseal","brdns","brdse", "bap","brap","bapal","bapz","brapz","bapzal", "beq","breq","beqal","beqz","breqz","beqzal", "bge","brge","bgeal","bgez","brgez","bgezal", "bgt","brgt","bgtal","bgtz","brgtz","bgtzal", "ble","brle","bleal","blez","brlez","blezal", "blt","brlt","bltal","bltz","brltz","bltzal", "bna","brna","bnaal","bnan","brnan","bnaz","brnaz","bnazal", "bne","brne","bneal","bnez","brnez","bnezal"
}
-- Build lookup table local opcode_lookup = {} for _, op in ipairs(opcodes) do
opcode_lookup[op] = true
end
local function highlight_line(line)
-- breaks strings in IC10 as it escapes "" line = mw.text.nowiki(line)
--minimal replacement instead
line = line
:gsub("&", "&")
:gsub("<", "<")
:gsub(">", ">")
-- comments
line = string.gsub(line, "(#.*)",
'%1')
-- labels
line = string.gsub(line, "^(%w+:)",
'%1')
-- r0–r9
line = string.gsub(line, "%f[%w]r[0-9]%f[%W]", '%0')
-- r10–r15
line = string.gsub(line, "%f[%w]r1[0-5]%f[%W]", '%0')
-- placeholder r?
line = string.gsub(line, "%f[%w]r%?", '%0')
-- devices d0–d5 plus d?
line = string.gsub(line, "%f[%w](d([0-5]|%?))%f[%W]",
'%1')
-- numbers hex
line = string.gsub(line, "%f[%w](%-?0x%x+)%f[%W]",
'%1')
-- numbers decimal
line = string.gsub(line, "%f[%w](%-?%d+)%f[%W]",
'%1')
-- opcodes
for op,_ in pairs(opcode_lookup) do
line = string.gsub(line,
"%f[%w]("..op..")%f[%W]",
'%1')
end
return line
end
function p.highlight(frame)
local text = frame.args[1] or "" local lines = mw.text.split(text, "\n")
for i,line in ipairs(lines) do
lines[i] = highlight_line(line)
end
return '
'
.. table.concat(lines, "\n") .. ''
end
return p