Hello, is it possible to list only properties without variables of an instance, object? For example if I use *$obj info vars* command it will give me all variables and properties names.
For example, is it possible to do it like that?
package require nx nx::Class create rClass { :property {prop1 "rprop"} }
nx::Class create tClass { :property {prop1 "tprop1"} :property {prop2:object, required} :variable cf "aaaa.ini"
:method init {} { puts "Init" } :public method a {} { return "Object is: ${:obj} | Config file is: ${:cf}" }
} set t [tClass new -prop2 [rClass new]]
foreach sl [$t info lookup variables] { if {[lindex [$t info variable definition $sl] 1] eq "property"} { puts "[$t info variable name $sl] is a property" } elseif {[lindex [$t info variable definition $sl] 1] eq "variable"} { puts "[$t info variable name $sl] is a variable" } }
Hi Maksym!
You might want to rely on the key discriminator between properties and variables in NX [1], whether the are configurable in terms of being accessible via cget/ configure. Then, you may simplify (FWIW) by asking each slot object whether it is configurable:
# returns all "properties"
lmap sl [$t info lookup variables] { if {[$sl cget -configurable]} {set sl} else continue }
There might be corner cases (e.g., properties/ variables without slot object), though, when this might fail you to retrieve all properties.
You might want to ask the "configure" method to return all configuration options specific to your application (i.e., not provided by the NX base classes):
lmap prop [$t info lookup parameters configure] { if {$prop ni [nx::Object info lookup parameters configure]} { set prop } else { continue } }]
HTH, for now, Stefan
[1] https://next-scripting.org/2.4.0/doc/nx/nx-migration/index1#_parameters
Hello, is it possible to list only properties without variables of an instance, object? For example if I use *$obj info vars* command it will give me all variables and properties names.
For example, is it possible to do it like that?
package require nx nx::Class create rClass { :property {prop1 "rprop"} } nx::Class create tClass { :property {prop1 "tprop1"} :property {prop2:object, required} :variable cf "aaaa.ini" :method init {} { puts "Init" } :public method a {} { return "Object is: ${:obj} | Config file is: ${:cf}" } } set t [tClass new -prop2 [rClass new]] foreach sl [$t info lookup variables] { if {[lindex [$t info variable definition $sl] 1] eq "property"} { puts "[$t info variable name $sl] is a property" } elseif {[lindex [$t info variable definition $sl] 1] eq "variable"} { puts "[$t info variable name $sl] is a variable" } }
Ooops, no closing bracket in last snippet, corrected:
lmap prop [$t info lookup parameters configure] { if {$prop ni [nx::Object info lookup parameters configure]} { set prop } else { continue } }
Hi Maksym!
You might want to rely on the key discriminator between properties and variables in NX [1], whether the are configurable in terms of being accessible via cget/ configure. Then, you may simplify (FWIW) by asking each slot object whether it is configurable:
# returns all "properties"
lmap sl [$t info lookup variables] { if {[$sl cget -configurable]} {set sl} else continue }
There might be corner cases (e.g., properties/ variables without slot object), though, when this might fail you to retrieve all properties.
You might want to ask the "configure" method to return all configuration options specific to your application (i.e., not provided by the NX base classes):
lmap prop [$t info lookup parameters configure] { if {$prop ni [nx::Object info lookup parameters configure]} { set prop } else { continue } }]
HTH, for now, Stefan
[1] https://next-scripting.org/2.4.0/doc/nx/nx-migration/index1#_parameters
Hello, is it possible to list only properties without variables of an instance, object? For example if I use *$obj info vars* command it will give me all variables and properties names.
For example, is it possible to do it like that?
package require nx nx::Class create rClass { :property {prop1 "rprop"} }
nx::Class create tClass { :property {prop1 "tprop1"} :property {prop2:object, required} :variable cf "aaaa.ini"
:method init {} { puts "Init" }
:public method a {} { return "Object is: ${:obj} | Config file is: ${:cf}" } } set t [tClass new -prop2 [rClass new]]
foreach sl [$t info lookup variables] { if {[lindex [$t info variable definition $sl] 1] eq "property"} { puts "[$t info variable name $sl] is a property" } elseif {[lindex [$t info variable definition $sl] 1] eq "variable"} { puts "[$t info variable name $sl] is a variable" } }