Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:IC10: Difference between revisions

From Stationeers Wiki
TK421 (talk | contribs)
fixing broken strings in IC10
TK421 (talk | contribs)
m highlight placeholder registers/devices as well.
Line 45: Line 45:
         '<span style="color:#dcdcaa;">%1</span>')
         '<span style="color:#dcdcaa;">%1</span>')


     -- registers r0–r15
     -- registers r0–r15 plus r?
     line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]))%f[%W]",
     line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]|%?))%f[%W]",
         '<span style="color:#4fc1ff;">%1</span>')
         '<span style="color:#4fc1ff;">%1</span>')


     -- devices d0–d5
     -- 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:#4fc1ff;">%1</span>')
         '<span style="color:#4fc1ff;">%1</span>')


     -- numbers hex
     -- numbers hex

Revision as of 06:32, 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')
   -- registers r0–r15 plus r?
   line = string.gsub(line, "%f[%w](r([0-9]|1[0-5]|%?))%f[%W]",
       '%1')
   -- 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