代码之家  ›  专栏  ›  技术社区  ›  Thufir

如何从tcl主脚本调用函数?

  •  0
  • Thufir  · 技术社区  · 5 年前

    我要通过 Tcl

    package provide weather  1.0
    package require Tcl      8.5
    
    namespace eval ::tutstack {
    }
    
    proc ::tutstack::hello {} {
        puts "hello world"
    }
    
    
    proc ::tutstack::sum {arg1 arg2} {
        set x [expr {$arg1 + $arg2}];
        return $x
    }
    
    proc ::tutstack::helloWorld {arg1} {
        return "hello plus arg"
    }
    

    从主:

    lappend auto_path /home/thufir/NetBeansProjects/spawnTelnet/telnet/api
    
    package require weather 1.0
    
    
    
    tutstack::hello
    
    set A 3
    set B 4
    
    puts [tutstack::sum $A $B]
    
    
    puts [tutstack::hello "fred"]
    

    错误:

    thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ 
    thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ tclsh main.tcl 
    hello world
    7
    wrong # args: should be "tutstack::hello"
        while executing
    "tutstack::hello "fred""
        invoked from within
    "puts [tutstack::hello "fred"]"
        (file "main.tcl" line 15)
    thufir@dur:~/NetBeansProjects/spawnTelnet/telnet$ 
    
    0 回复  |  直到 5 年前
        1
  •  0
  •   Thufir    5 年前

    哎呀:

    lappend auto_path /home/thufir/NetBeansProjects/spawnTelnet/telnet/api
    
    package require weather 1.0
    
    
    
    tutstack::hello
    
    set A 3
    set B 4
    
    puts [tutstack::sum $A $B]
    
    
    puts [tutstack::helloWorld "fred"]
    

    谢谢,格伦