Gnocl Cookbook‎ > ‎

Playing Subsitutions Strings

# object builder
proc myObj {} {

    set id obj_[incr ::Objs]

    # initialize empty data
    set ::eng($id) ""
    set ::cback($id) ""
    set ::con($id) ""
    set ::src($id) ""
    set ::tgt($id) ""
   
    proc ::$id {} {
        set id [lindex [::info level 0] 0]
        subExec $id
    }
   
    return $id
}

    # create an instance, and assign some values
    set id [myObj]

    set ::eng($id) AAAAA_1
    set ::cback($id) "myCallBack add %s %t %c"
    set ::con($id) "我即以神足往告釋梵護世"
    set ::src($id) 神
    set ::tgt($id) magical

# link this to some event trigger..
proc subExec {id} {

    set subStr [list %e $::eng($id) %c $::con($id) %s $::src($id) %t $::tgt($id)]
    {*}[string map $subStr $::cback($id) ]
}

$id
Comments