Parse a tcl word into a list of tcl commands ready for eval or uplevel -
i want write function can used this:
my_function { cmda arga_1 arga_2 cmdb argb_1 argb_2 cmdc argc_1 argc_2 }
i want implement my_function using namespace eval ::my_internal_namespace [uplevel ...]
, perchance in loop. although not useful, enhance later more simply uplevel
.
my_internal_namespace
defined this:
namespace eval my_internal_namespace { proc cmda { args } { puts "$args" } proc cmdb { args } { puts "$args" } proc cmdc { args } { puts "$args" } }
i think technique allow caller of my_function declare facts , behaviours my_function, parameters of facts , behaviours evaluated in context of caller, example, value of variables or perform other substitutions in namespace , scope of caller.
why not pass word namespace eval
directly? that's almost tcl in situations oo::define
command. evaluate script wonderfully easy way parse trusted code.
namespace eval ::my_internal_namespace $the_user_word
for untrusted code, safe interpreter recommended. these “little language” approaches, you're best create basic safe interpreter, hide remaining commands don't want expose, , add together in aliases commands want create available.
set [interp create -safe] foreach cmd [$i eval {info commands}] { $i hide $cmd } foreach cmd {cmda cmdb cmdc} { $i alias $cmd ::my_internal_namespace::$cmd } $i eval $the_user_word
this expensive doing namespace eval
; wouldn't bother if code relatively trusted.
tcl
No comments:
Post a Comment