Posted 13 July 2015 - 06:38 PM
For my latest Redstone Engine (The first one might be in my signature),
I save the instructions to a file as code
An example file:
Creating and saving is working great. My problem is reading the code again to be able to edit it.
I'd like to use string patterns to extract the arguments from the functions
Like this:
All the functions:
See spoiler below for ones I've completed
(All arguments should be returned as strings, side needs its quotes still)
NOTE I'd like 4 separate patterns, not one for all 4
( Is one for all 4 even possible? )
I save the instructions to a file as code
An example file:
rs.setOutput("right",true)
sleep(1)
rs.setOutput("right",false)
Creating and saving is working great. My problem is reading the code again to be able to edit it.
I'd like to use string patterns to extract the arguments from the functions
Like this:
local func = [[rs.setOutput("right",true)]]
args = { string.match( func , "pattern") } --# Is it gmatch? EDIT: No, its string.match
print( textutils.serialize( args ) )
Expected Output:
{
"\"right\"",
"true",
}
All the functions:
See spoiler below for ones I've completed
(All arguments should be returned as strings, side needs its quotes still)
rs.setOutput("side",state) --#> "side",state
rs.setBundledOutput("side",number) --#> "side",number
rs.setBundledOutput("side",colors.combine(rs.getBundledOutput("side"),number)) --#> "side",number
rs.setBundledOutput("side",colors.subtract(rs.getBundledOutput("side"),number)) --#> "side",number
Spoiler
print( string.match( [[rs.setBundeldOutput("right",120)]] , [[rs.setBundledOutput(%(("a+"),(%d+)%)]] ) --#> "right" , 120 (two variables)
print( string.match( [[rs.setBundledOutput("right",colors.subtract(rs.getBundledOutput("right"),2))]] ,[[rs.setBundledOutput%(("%a+"),colors.subtract%(rs.getBundledOutput%("%a+"%),(%d+)%)%)]]) --#> "right" , 2
NOTE I'd like 4 separate patterns, not one for all 4
( Is one for all 4 even possible? )
Edited on 13 July 2015 - 07:12 PM