miau wrote:using the macros like this:
Code: Select all
peng::particle_create #01
peng::particle_setpos #40,#120
doesn't work.
Macros seem to be directly accessible from all scopes(?), so just calling them without the "peng::" part works. That defies the purpose of scopes, though.
My questions: Is there any way around this? Is it even good practice to write code like this or is there a better, recommended way?
It's the first time I've been using scopes in this way, but I've got older similar code that I want to convert to be more readable and organized.
<Insert apology about necro-bump here>
I also wanted to keep things more readable and organized, I figured you can force yourself to use a scope-like syntax without any obvious (so far) downside. One can create a macro with the same name as the scope that acts as a fake scope/namespace and then calls the macro that was intended. Example code:
Code: Select all
.macro SCOPE_NAME name_param1, param2, param3, param4, param5, param6, param7, param8, param9, param10
aPrivateScope::interfaceValid .set 1
.if .not .xmatch(.mid(0,1,{name_param1}),::)
.error "Scope operator expected."
.exitmacro
.else
.ifnblank param10
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}, {param6}, {param7}, {param8}, {param9}, {param10}
.elseif .not .blank( param9 )
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}, {param6}, {param7}, {param8}, {param9}
.elseif .not .blank( param8 )
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}, {param6}, {param7}, {param8}
.elseif .not .blank( param7 )
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}, {param6}, {param7}
.elseif .not .blank( param6 )
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}, {param6}
.elseif .not .blank( param5 )
.define __PARAMS__ , {param2}, {param3}, {param4}, {param5}
.elseif .not .blank( param4 )
.define __PARAMS__ , {param2}, {param3}, {param4}
.elseif .not .blank( param3 )
.define __PARAMS__ , {param2}, {param3}
.elseif .not .blank( param2 )
.define __PARAMS__ , {param2}
.else
.define __PARAMS__
.endif
.if .tcount({name_param1}) = 2 ; scope operator and name, no first param, maybe other params
.mid(1,1,{name_param1}) __PARAMS__
.elseif .tcount({name_param1}) >= 3 ; scope operator, name and param1, maybe other params
.mid(1,1,{name_param1}) .mid(2,255,{name_param1}) __PARAMS__
.else
.error "Syntax Error."
.endif
.undefine __PARAMS__
.endif
.endif
aPrivateScope::interfaceValid .set 0
.endmacro
.macro checkInterface
.if .not aPrivateScope::interfaceValid
.error "Please use the proper interface syntax."
.endif
.endmacro
For each macro that is a part of the scope the first line should be 'checkInterface', to make sure you used the namespace:: syntax. There might be a sneaker way to deal with multiple paramaters. Edit: add curly brackets. Edit: more robust code.