Forum OpenACS Q&A: How do you call a procedure from a different tcl file

This is basic TCL programming and I can do this outside of OpenACS, but I cannot find documents or examples of how to call a procedure from one tcl file to another tcl file.

Example: There two tcl files
1. main.tcl
2. helloworld.tcl
within "helloworld.tcl" is the procedure "hello word"

Within main.tcl, I would like to call (invoke) "hello world" procedure

I tried using the source command, but this do not work.

Any guidance would be appreciated.

Hello Tyge,

there must be something we are overlooking here. What exactly does not work? Is there any error message you could share?

Is this in the context of an OpenACS project? Is this code you are trying to import yours or some external library?

Ciao

Dear Tyge,

since your question is about plain Tcl, it is probably better to ask this question on e.g. comp.lang.tcl.

A short answer is that if you want to call a proc from a script, the proc has to be defined first. One can load procs defined in a script by sourcing it [1] or by defining packages [2].

In the OpenACS-case, the API is preloaded from all the library files into a "blueprint" (containing all procs), which is made available to the requests and background jobs.

[1] https://www.tcl.tk/man/tcl8.5/tutorial/Tcl30.html
[2] https://www.tcl.tk/man/tcl8.5/tutorial/Tcl31.html

Collapse
Posted by Tyge Cawthon on
Thank you. This is what I was looking for. Your help is very much appreciated.

My plan is first to understand how these procedures work in plain TCL then, lean how they work in OpenACS.

Thanks again.