Using "source" vs "package require" for Tcl application files

tcl

    Next

  • 1. Running a Tk application through EMACS crashes when opening file dialog boxes
    Hello, I am just getting started using EMACS and I love the fact that I can run my application and reload functions into the interpreter without restarting the app. The only catch I have found is that when my app calls any file dialog box such as tk_getOpenFile or tk_chooseDirectory it hangs and must be killed and restarted. Other dialogs like tk_messageBox work fine. Any ideas on what could be wrong? I am using WinXP SP2, EMACS 22.0.50.1 and activestate tcl 8.4.13 Thanks, Nathan
  • 2. How do I clear the wish "workspace"
    Is there a way to reset the wish workspace back to the original load after having a program fail. I often simply use Notepad (Windows XP) to edit my programs and "source" them into wish. But how do I clear out the crud my failed program has put into the workspace, like window xxx already exists...
  • 3. "Error : integer value too large" when converting hexa to binary via binary format/scan
    Hi, This procedure work till no big (1010000000000000000000000000000110011010) binary is converted. proc Hexa2Bin { hexa } { binary scan [binary format I $hexa] B* binStr puts "$binStr" } Hexa2Bin 0x00000000000000019A -> 00000000000000000000000110011010 Hexa2Bin 0x00000000A00000019A -> Error: integer value too large to represent while executing "format %x $hexa" (procedure "hexa2Bin" line 2) invoked from within "hexa2Bin $hexa" (file "conv.tcl" line 15) while should return 1010000000000000000000000000000110011010 I am a little desperated. Hope someone can help asap. Thanks in advance (-: Leslie.

Using "source" vs "package require" for Tcl application files

Postby GB » Wed, 31 Dec 2008 09:04:31 GMT

I would like to divide my Tcl application into separate files. Should I 
generally use "source" to combine the files, or should I use the package 
mechanism (package provide, package require, etc.)?

What is the generally accepted practice?

Thanks,

Gregg

Re: Using "source" vs "package require" for Tcl application files

Postby Arjen Markus » Wed, 31 Dec 2008 16:49:32 GMT



IMHO use [source]. My reasoning:

- The package mechanism is meant for getting access to
  general-purpose libraries, installed directly under the Tcl
  installation.

- You talk of source files for your own application. So I would
  expect these files to reside in a directory containing that
  application. Then [source] is easier to use - and you guarantee
  that you get the source files from your application (otherwise
  a random package with the same name from the installation
  could interfer, if you are not careful with the library path)

- Using [source] also makes it clear that these files are meant
  for your application only, not for more general purposes.

Regards,

Arjen

Re: Using "source" vs "package require" for Tcl application files

Postby GB » Wed, 31 Dec 2008 18:24:27 GMT





Thanks. That was my initial inclination, but I was confused after 
reading Practical Programming in Tcl, Chapter 12. In the section 
"Locating Packages", it says:

 > One trick I often use is to put the directory containing the
 > main script into the auto_path. The following command sets this
 > up:

 > lappend auto_path [file dirname [info script]]

 > If your code is split into bin and lib directories, then
 > scripts in the bin directory can add the adjacent lib directory
 > to their auto_path with this command:

 > lappend auto_path \

 >     [file join [file dirname [info script]] ../lib]

Gregg

Re: Using "source" vs "package require" for Tcl application files

Postby Arjen Markus » Wed, 31 Dec 2008 19:04:16 GMT






> > general-purpose libraries, installed directly under the Tcl
>>>> installation.>
>>
> > - You talk of source files for your own application. So I would>
> > expect these files to reside in a directory containing tha>
>> > application. Then [source] is easier to use - and you guarant>e>
> > that you get the source files from your application (otherw>s>
> > a random package with the same name from the installa>i>n
> > could interfer, if you are not careful with the library >at>)>
>
> > - Using [source] also makes it clear that these files are >e>nt
> > for your application only, not for more general pur>os>s>
>
> > Re>ar>s>
>
> >>Ar>en
>
> Thanks. That was my initial inclination, but I was confused>after
> reading Practical Programming in Tcl, Chapter 12. In the s>ction
> "Locating Packages", it>sa>s:
>
>  One trick I often use is to put the directory contain>ng the
>  main script into the auto_path. The following command s>ts this
>> >> up:
>
>  lappend auto_path [file dirname [inf> s>ript]]
>
>  If your code is split into bin and lib direct>ries, then
>  scripts in the bin directory can add the adjacent l>b directory
>  to their auto_path with >hi> command:
>
>  lappe>d >uto_path \
>
>  [file join [file dirname [info>sc>ipt]] ../lib]
>
> Gregg- Tekst uit oorspronkelijk bericht>ni>t weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

Right, but that refers to the old (ancient?) way of loading Tcl files,
via
the auto loading mechanism - not packages perse.

Myself, I do not use that mechanism (at least not consciously ;)).

Regards,

Arjen

Re: Using "source" vs "package require" for Tcl application files

Postby Ron Fox » Wed, 31 Dec 2008 21:00:42 GMT

I'll use a similar trick if the application is structured in packages, 
however I'll _prepend_ the directory the app lives in rather than 
append.  That deals with the issue of package name clashes.. ensuring 
it's resolved in favor of _my_ packages.

e.g. rather than lapped auto_path [file dirname [info script]]

set auto_path [concat [file dirname [info script]] $auto_path]

RF.









-- 
Ron Fox
NSCL
Michigan State University
East Lansing, MI 48824-1321

Re: Using "source" vs "package require" for Tcl application files

Postby Gerald W. Lester » Thu, 01 Jan 2009 01:43:24 GMT



or: set auto_path [linsert [file dirname [info script]] 0]

-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Re: Using "source" vs "package require" for Tcl application files

Postby Glenn Jackman » Thu, 01 Jan 2009 22:58:16 GMT





you mean:
       set auto_path [linsert $auto_path 0 [file dirname [info script]]]


-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous

Re: Using "source" vs "package require" for Tcl application files

Postby Gerald W. Lester » Sat, 03 Jan 2009 02:18:12 GMT







Yes, I did.


-- 
+------------------------------------------------------------------------+
| Gerald W. Lester                                                       |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Similar Threads:

1.bug using TCL command "package require" embedded in C

Hello to all,
I m trying to run serveral TCL commands inside C++ source code and
when I show the information of the auto_path it is empty.
If I put the same command in the tclsh interpreter it runs well.

What Am I doing bad?
in tclsh I insert:
puts $auto_path
puts hola
package require Tk

and runs well.

my c souce code is the next:
#include <tcl.h>
#include <stdlib.h>
int main(int argc, char**argv) {
    Tcl_Interp *interp;
    int status;
    char *comandos[] = { "puts $auto_path","set auto_path /usr/
lib/","puts $auto_path","auto_load","puts hola",
            "package require Tk", "package require clock",
            , "", NULL };
    interp = Tcl_CreateInterp();
    if (interp == NULL) {
        printf("can not create tcl interpreter\n");
        exit(EXIT_FAILURE);
    }
    int i = 0;
    Tcl_Obj *obj;
    while (comandos[i] != NULL) {
        status = Tcl_Eval(interp, comandos[i]);
        if (interp->result[0] != 0) {
            printf("%s\n", interp->result);
        }
        i++;
    }
    return EXIT_SUCCESS;
}

The result of the execution is:
can't read "auto_path": no such variable
/usr/lib/
/usr/lib/
invalid command name "auto_load"
hola
can't find package Tk
can't find package clock
can't find package AglClient

2.Finding Expect package using Embedded TCL in C++ Application

Hi,

I'm trying to run an expect script from a C++ application that is
embedding TCL in it. I am only running a few TCL commands at this
point. The code looks somewhat like this:

Tcl_FindExecutable("myApp.exe");
myInterpreter = Tcl_CreateInterp();
ret = Tcl_EvalFile(myInterpreter,scriptpath);

This code passes if I use simple TCL commands in my script like puts.
I can load external module as well, however, one particular script I'm
trying to run includes the following line at the top.

package require Expect

Running this, I get the result "can't find package Expect" from
Tcl_GetStringResult(myInterpreter)...

I'm wondering if maybe I need to run some kind of initialization
function. I thought maybe I have some path errors when I launch my
Interpreter that are not resolved when I try to load the Expect
Package.

Any ideas?
Jonathan

3.package require tcldotnet or package require tclmono

I'm just wondering how difficult it would be to implement a package
that would allow the use of dotnet or mono.

package require tcldotnet

or

package require tclmono

4.Packaging Tcl/Tk Application on Windows: Single File Executable

Hi all,

I need to package application developed in Tcl/Tk on Windows. It should
be a single file executable with all data files (gifs), dependency
packages such as winico bundled into a single executable.

There should be not reference to external data files such as images ..
All should be bundled as a single file on desktop.

I have used mktclapp and also freewrap but one needs to keep the image
files separate.

Do I have to change code to include the image files data ?

Thanks in advance,
Andy

5.Zip file/Zip Executable vs StarKit/StarPacks [Was: Tcl application deployment

6. Package require in tcl 8.5.1

7. unnecessary package require in msgcat.tcl

8. [TCL] Strange behavior, or so I think, for package require



Return to tcl

 

Who is online

Users browsing this forum: No registered users and 53 guest