Module:IC10: Difference between revisions
More actions
m replace mw.text.gsub with string.gsub |
Add LogicTypes for new gasses/liquids |
||
| (22 intermediate revisions by 2 users not shown) | |||
| Line 3: | Line 3: | ||
-- List of IC10 opcodes (all strings) | -- List of IC10 opcodes (all strings) | ||
local opcodes = { | local opcodes = { | ||
"add","sub"," | "alias","define","hcf","yield", | ||
"and","or","xor"," | "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 | -- Build lookup table for opcodes | ||
local opcode_lookup = {} | local opcode_lookup = {} | ||
for _, op in ipairs(opcodes) do | for _, op in ipairs(opcodes) do | ||
opcode_lookup[op] = true | opcode_lookup[op] = true | ||
end | |||
-- list of parameters | |||
local parameters = { --taken from Assets.Scripts.Objects.Motherboards:LogicType | |||
"None","Power","Open","Mode","Error", | |||
"Pressure","Temperature","PressureExternal","PressureInternal", | |||
"Activate","Lock","Charge","Setting", | |||
"Reagents", | |||
"RatioOxygen","RatioCarbonDioxide","RatioNitrogen","RatioPollutant","RatioVolatiles","RatioWater", | |||
"Horizontal","Vertical","SolarAngle","Maximum", | |||
"Ratio", | |||
"PowerPotential","PowerActual", | |||
"Quantity", | |||
"On", | |||
"ImportQuantity","ImportSlotOccupant","ExportQuantity","ExportSlotOccupant", | |||
"RequiredPower", | |||
"HorizontalRatio","VerticalRatio", | |||
"PowerRequired","Idle", | |||
"Color", | |||
"ElevatorSpeed","ElevatorLevel", | |||
"RecipeHash", | |||
"ExportSlotHash","ImportSlotHash", | |||
"PlantHealth1","PlantHealth2","PlantHealth3","PlantHealth4", --i think these are deprecated. | |||
"PlantGrowth1","PlantGrowth2","PlantGrowth3","PlantGrowth4", | |||
"PlantEfficiency1","PlantEfficiency2","PlantEfficiency3","PlantEfficiency4", | |||
"PlantHash1","PlantHash2","PlantHash3","PlantHash4", | |||
"RequestHash","CompletionRatio","ClearMemory","ExportCount","ImportCount", | |||
"PowerGeneration", | |||
"TotalMoles","Volume", | |||
"Plant","Harvest","Output", | |||
"PressureSetting","TemperatureSetting","TemperatureExternal","Filtration","AirRelease", | |||
"PositionX","PositionY","PositionZ", | |||
"VelocityMagnitude","VelocityRelativeX","VelocityRelativeY","VelocityRelativeZ", | |||
"RatioNitrousOxide", | |||
"PrefabHash", | |||
"ForceWrite", | |||
"SignalStrength","SignalID","TargetX","TargetY","TargetZ","SettingInput","SettingOutput", | |||
"CurrentResearchPodType","ManualResearchRequiredPod", | |||
"MineablesInVicinity","MineablesInQueue", | |||
"NextWeatherEventTime", | |||
"Combustion", | |||
"Fuel","ReturnFuelCost","CollectableGoods", | |||
"Time","Bpm", | |||
"EnvironmentEfficiency","WorkingGasEfficiency", | |||
"PressureInput","TemperatureInput", | |||
"RatioOxygenInput","RatioCarbonDioxideInput","RatioNitrogenInput","RatioPollutantInput","RatioVolatilesInput","RatioWaterInput","RatioNitrousOxideInput", | |||
"TotalMolesInput", | |||
"PressureInput2","TemperatureInput2", | |||
"RatioOxygenInput2","RatioCarbonDioxideInput2","RatioNitrogenInput2","RatioPollutantInput2","RatioVolatilesInput2","RatioWaterInput2","RatioNitrousOxideInput2", | |||
"TotalMolesInput2", | |||
"PressureOutput","TemperatureOutput", | |||
"RatioOxygenOutput","RatioCarbonDioxideOutput","RatioNitrogenOutput","RatioPollutantOutput","RatioVolatilesOutput","RatioWaterOutput","RatioNitrousOxideOutput", | |||
"TotalMolesOutput", | |||
"PressureOutput2","TemperatureOutput2", | |||
"RatioOxygenOutput2","RatioCarbonDioxideOutput2","RatioNitrogenOutput2","RatioPollutantOutput2","RatioVolatilesOutput2","RatioWaterOutput2","RatioNitrousOxideOutput2", | |||
"TotalMolesOutput2", | |||
"CombustionInput","CombustionInput2","CombustionOutput","CombustionOutput2", | |||
"OperationalTemperatureEfficiency","TemperatureDifferentialEfficiency","PressureEfficiency", | |||
"CombustionLimiter","Throttle","Rpm","Stress", | |||
"InterrogationProgress","TargetPadIndex","SizeX","SizeY","SizeZ","MinimumWattsToContact","WattsReachingContact", | |||
"Channel0","Channel1","Channel2","Channel3","Channel4","Channel5","Channel6","Channel7", | |||
"LineNumber", | |||
"Flush","SoundAlert", | |||
"SolarIrradiance", | |||
"RatioLiquidNitrogen","RatioLiquidNitrogenInput","RatioLiquidNitrogenInput2","RatioLiquidNitrogenOutput","RatioLiquidNitrogenOutput2", | |||
"VolumeOfLiquid", | |||
"RatioLiquidOxygen","RatioLiquidOxygenInput","RatioLiquidOxygenInput2","RatioLiquidOxygenOutput","RatioLiquidOxygenOutput2", | |||
"RatioLiquidVolatiles","RatioLiquidVolatilesInput","RatioLiquidVolatilesInput2","RatioLiquidVolatilesOutput","RatioLiquidVolatilesOutput2", | |||
"RatioSteam","RatioSteamInput","RatioSteamInput2","RatioSteamOutput","RatioSteamOutput2", | |||
"ContactTypeId", | |||
"RatioLiquidCarbonDioxide","RatioLiquidCarbonDioxideInput","RatioLiquidCarbonDioxideInput2","RatioLiquidCarbonDioxideOutput","RatioLiquidCarbonDioxideOutput2", | |||
"RatioLiquidPollutant","RatioLiquidPollutantInput","RatioLiquidPollutantInput2","RatioLiquidPollutantOutput","RatioLiquidPollutantOutput2", | |||
"RatioLiquidNitrousOxide","RatioLiquidNitrousOxideInput","RatioLiquidNitrousOxideInput2","RatioLiquidNitrousOxideOutput","RatioLiquidNitrousOxideOutput2", | |||
"Progress","DestinationCode","Acceleration","ReferenceId","AutoShutOff","Mass","DryMass","Thrust","Weight","ThrustToWeight","TimeToDestination","BurnTimeRemaining", | |||
"AutoLand","ForwardX","ForwardY","ForwardZ","Orientation","VelocityX","VelocityY","VelocityZ", | |||
"PassedMoles","ExhaustVelocity", | |||
"FlightControlRule","ReEntryAltitude","Apex", | |||
"EntityState","DrillCondition", | |||
"Index","CelestialHash","AlignmentError","DistanceAu","OrbitPeriod","Inclination","Eccentricity","SemiMajorAxis","DistanceKm","CelestialParentHash","TrueAnomaly", | |||
"RatioHydrogen","RatioLiquidHydrogen","RatioPollutedWater", | |||
"Discover","Chart","Survey","NavPoints","ChartedNavPoints","Sites","CurrentCode","Density","Richness","Size","TotalQuantity","MinedQuantity", | |||
"BestContactFilter", | |||
"NameHash", | |||
"Altitude", | |||
"TargetSlotIndex","TargetPrefabHash", | |||
"Extended", | |||
"NetworkFault", | |||
"ProportionalGain","IntegralGain","DerivativeGain","Minimum","Setpoint","Reset", | |||
"StackSize", | |||
"NextWeatherHash", | |||
"ContactSlotIndex", | |||
"RatioHydrazine","RatioLiquidHydrazine","RatioLiquidAlcohol","RatioHelium","RatioLiquidSodiumChloride","RatioSilanol","RatioLiquidSilanol", | |||
"RatioHydrochloricAcid","RatioLiquidHydrochloricAcid","RatioOzone","RatioLiquidOzone" | |||
} | |||
table.insert(parameters, "Sum") --these weren't on that list. | |||
table.insert(parameters, "Average") | |||
-- Build lookup table for parameters | |||
local parameter_lookup = {} | |||
for _, par in ipairs(parameters) do | |||
parameter_lookup[par] = true | |||
end | end | ||
local function highlight_line(line) | local function highlight_line(line) | ||
line = mw.text.nowiki(line) | -- breaks strings in IC10 as it escapes "" line = mw.text.nowiki(line) | ||
--minimal replacement instead | |||
line = line | |||
:gsub("&", "&") | |||
:gsub("<", "<") | |||
:gsub(">", ">") | |||
-- comments | -- comments | ||
line = string.gsub(line, "(#.*)", | line = string.gsub(line, "(#.*)", | ||
'<span style="color:# | '<span style="color:#7f8c8d;font-style:italic;">%1</span>') | ||
-- labels | -- labels | ||
line = string.gsub(line, "^(%w+:)", | line = string.gsub(line, "^(%w+:)", | ||
'<span style="color:# | '<span style="color:#0d1b2a;">%1</span>') | ||
-- r0–r9 | |||
line = string.gsub(line, "%f[%w]r[0-9]%f[%W]", '<span style="color:#4fc1ff;">%0</span>') | |||
-- | -- r10–r15 | ||
line = string.gsub(line, "%f[%w] | line = string.gsub(line, "%f[%w]r1[0-5]%f[%W]", '<span style="color:#4fc1ff;">%0</span>') | ||
'<span style="color:# | |||
-- placeholder r? | |||
line = string.gsub(line, "%f[%w]r%?", '<span style="color:#4fc1ff;">%0</span>') | |||
-- real devices d0–d5 | |||
line = string.gsub(line, "%f[%w]d[0-5]%f[%W]", | |||
'<span style="color:#3BD14F;">%0</span>') | |||
-- placeholder d? | |||
line = string.gsub(line, "%f[%w]d%?", | |||
'<span style="color:#3BD14F;">%0</span>') | |||
-- numbers hex | -- numbers hex | ||
line = string.gsub(line, "% | line = string.gsub(line, "(%$[%da-fA-F]+)%f[%W]", | ||
'<span style="color:# | '<span style="color:#4dd0e1;">%1</span>') | ||
-- numbers decimal | -- numbers decimal | ||
line = string.gsub(line, "%f[%w](%-?%d+)%f[%W]", | line = string.gsub(line, "%f[%w](%-?%d+)%f[%W]", | ||
'<span style="color:# | '<span style="color:#4dd0e1;">%1</span>') | ||
-- opcodes | -- opcodes | ||
| Line 41: | Line 175: | ||
line = string.gsub(line, | line = string.gsub(line, | ||
"%f[%w]("..op..")%f[%W]", | "%f[%w]("..op..")%f[%W]", | ||
'<span style="color:# | '<span style="color: #b58900; font-weight: bold;">%1</span>') | ||
end | |||
-- parameters | |||
for par,_ in pairs(parameter_lookup) do | |||
line = string.gsub(line, | |||
"%f[%w]("..par..")%f[%W]", | |||
'<span style="color: #F39C12; font-weight: bold;">%1</span>') | |||
end | end | ||
| Line 55: | Line 196: | ||
end | end | ||
return '<pre style="font-family:monospace; background-color:# | return '<pre style="font-family:monospace; background-color:#0d1b2a; border:1px solid #1b263b; white-space:pre; display:block; padding:8px; color:#ffffff;">' | ||
.. table.concat(lines, "\n") .. '</pre>' | |||
end | end | ||
return p | return p | ||
Latest revision as of 14:00, 24 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 for opcodes local opcode_lookup = {} for _, op in ipairs(opcodes) do
opcode_lookup[op] = true
end
-- list of parameters local parameters = { --taken from Assets.Scripts.Objects.Motherboards:LogicType "None","Power","Open","Mode","Error", "Pressure","Temperature","PressureExternal","PressureInternal", "Activate","Lock","Charge","Setting", "Reagents", "RatioOxygen","RatioCarbonDioxide","RatioNitrogen","RatioPollutant","RatioVolatiles","RatioWater", "Horizontal","Vertical","SolarAngle","Maximum", "Ratio", "PowerPotential","PowerActual", "Quantity", "On", "ImportQuantity","ImportSlotOccupant","ExportQuantity","ExportSlotOccupant", "RequiredPower", "HorizontalRatio","VerticalRatio", "PowerRequired","Idle", "Color", "ElevatorSpeed","ElevatorLevel", "RecipeHash", "ExportSlotHash","ImportSlotHash", "PlantHealth1","PlantHealth2","PlantHealth3","PlantHealth4", --i think these are deprecated. "PlantGrowth1","PlantGrowth2","PlantGrowth3","PlantGrowth4", "PlantEfficiency1","PlantEfficiency2","PlantEfficiency3","PlantEfficiency4", "PlantHash1","PlantHash2","PlantHash3","PlantHash4", "RequestHash","CompletionRatio","ClearMemory","ExportCount","ImportCount", "PowerGeneration", "TotalMoles","Volume", "Plant","Harvest","Output", "PressureSetting","TemperatureSetting","TemperatureExternal","Filtration","AirRelease", "PositionX","PositionY","PositionZ", "VelocityMagnitude","VelocityRelativeX","VelocityRelativeY","VelocityRelativeZ", "RatioNitrousOxide", "PrefabHash", "ForceWrite", "SignalStrength","SignalID","TargetX","TargetY","TargetZ","SettingInput","SettingOutput", "CurrentResearchPodType","ManualResearchRequiredPod", "MineablesInVicinity","MineablesInQueue", "NextWeatherEventTime", "Combustion", "Fuel","ReturnFuelCost","CollectableGoods", "Time","Bpm", "EnvironmentEfficiency","WorkingGasEfficiency", "PressureInput","TemperatureInput", "RatioOxygenInput","RatioCarbonDioxideInput","RatioNitrogenInput","RatioPollutantInput","RatioVolatilesInput","RatioWaterInput","RatioNitrousOxideInput", "TotalMolesInput", "PressureInput2","TemperatureInput2", "RatioOxygenInput2","RatioCarbonDioxideInput2","RatioNitrogenInput2","RatioPollutantInput2","RatioVolatilesInput2","RatioWaterInput2","RatioNitrousOxideInput2", "TotalMolesInput2", "PressureOutput","TemperatureOutput", "RatioOxygenOutput","RatioCarbonDioxideOutput","RatioNitrogenOutput","RatioPollutantOutput","RatioVolatilesOutput","RatioWaterOutput","RatioNitrousOxideOutput", "TotalMolesOutput", "PressureOutput2","TemperatureOutput2", "RatioOxygenOutput2","RatioCarbonDioxideOutput2","RatioNitrogenOutput2","RatioPollutantOutput2","RatioVolatilesOutput2","RatioWaterOutput2","RatioNitrousOxideOutput2", "TotalMolesOutput2", "CombustionInput","CombustionInput2","CombustionOutput","CombustionOutput2", "OperationalTemperatureEfficiency","TemperatureDifferentialEfficiency","PressureEfficiency", "CombustionLimiter","Throttle","Rpm","Stress", "InterrogationProgress","TargetPadIndex","SizeX","SizeY","SizeZ","MinimumWattsToContact","WattsReachingContact", "Channel0","Channel1","Channel2","Channel3","Channel4","Channel5","Channel6","Channel7", "LineNumber", "Flush","SoundAlert", "SolarIrradiance", "RatioLiquidNitrogen","RatioLiquidNitrogenInput","RatioLiquidNitrogenInput2","RatioLiquidNitrogenOutput","RatioLiquidNitrogenOutput2", "VolumeOfLiquid", "RatioLiquidOxygen","RatioLiquidOxygenInput","RatioLiquidOxygenInput2","RatioLiquidOxygenOutput","RatioLiquidOxygenOutput2", "RatioLiquidVolatiles","RatioLiquidVolatilesInput","RatioLiquidVolatilesInput2","RatioLiquidVolatilesOutput","RatioLiquidVolatilesOutput2", "RatioSteam","RatioSteamInput","RatioSteamInput2","RatioSteamOutput","RatioSteamOutput2", "ContactTypeId", "RatioLiquidCarbonDioxide","RatioLiquidCarbonDioxideInput","RatioLiquidCarbonDioxideInput2","RatioLiquidCarbonDioxideOutput","RatioLiquidCarbonDioxideOutput2", "RatioLiquidPollutant","RatioLiquidPollutantInput","RatioLiquidPollutantInput2","RatioLiquidPollutantOutput","RatioLiquidPollutantOutput2", "RatioLiquidNitrousOxide","RatioLiquidNitrousOxideInput","RatioLiquidNitrousOxideInput2","RatioLiquidNitrousOxideOutput","RatioLiquidNitrousOxideOutput2", "Progress","DestinationCode","Acceleration","ReferenceId","AutoShutOff","Mass","DryMass","Thrust","Weight","ThrustToWeight","TimeToDestination","BurnTimeRemaining", "AutoLand","ForwardX","ForwardY","ForwardZ","Orientation","VelocityX","VelocityY","VelocityZ", "PassedMoles","ExhaustVelocity", "FlightControlRule","ReEntryAltitude","Apex", "EntityState","DrillCondition", "Index","CelestialHash","AlignmentError","DistanceAu","OrbitPeriod","Inclination","Eccentricity","SemiMajorAxis","DistanceKm","CelestialParentHash","TrueAnomaly", "RatioHydrogen","RatioLiquidHydrogen","RatioPollutedWater", "Discover","Chart","Survey","NavPoints","ChartedNavPoints","Sites","CurrentCode","Density","Richness","Size","TotalQuantity","MinedQuantity", "BestContactFilter", "NameHash", "Altitude", "TargetSlotIndex","TargetPrefabHash", "Extended", "NetworkFault", "ProportionalGain","IntegralGain","DerivativeGain","Minimum","Setpoint","Reset", "StackSize", "NextWeatherHash", "ContactSlotIndex", "RatioHydrazine","RatioLiquidHydrazine","RatioLiquidAlcohol","RatioHelium","RatioLiquidSodiumChloride","RatioSilanol","RatioLiquidSilanol", "RatioHydrochloricAcid","RatioLiquidHydrochloricAcid","RatioOzone","RatioLiquidOzone" } table.insert(parameters, "Sum") --these weren't on that list. table.insert(parameters, "Average")
-- Build lookup table for parameters local parameter_lookup = {} for _, par in ipairs(parameters) do
parameter_lookup[par] = 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')
-- real devices d0–d5
line = string.gsub(line, "%f[%w]d[0-5]%f[%W]",
'%0')
-- placeholder d?
line = string.gsub(line, "%f[%w]d%?",
'%0')
-- numbers hex
line = string.gsub(line, "(%$[%da-fA-F]+)%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
-- parameters
for par,_ in pairs(parameter_lookup) do
line = string.gsub(line,
"%f[%w]("..par..")%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