Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

TCL(Tool Command Language) Scripting

how to load a package in a Tcl_Interp?


Hi everyone,

I wrote a C program to use the tcl snack package. When I create a
Tcl_Interp in my program,I found that the Tcl_Interp includes only the
tcl package. When the program invoked the command "sound s -file
m1.wav", it failed with error msg"invalid command name 'sound' ".
Could someone tell me how to load the snack package in a Tcl_Interp?
Thanks in advance.

My program is attached as below.

#include<stdio.h>
#include<stdlib.h>
#include<tcl.h>

int main(int argc, _TCHAR* argv[])
{
        Tcl_Interp *pTclInterp = Tcl_CreateInterp();
        if(!pTclInterp)
        {
                printf("Tcl Interpreter could not be created.\n");
                return 0;
        }
        Tcl_Eval(pTclInterp," puts \"Hello ,world !\"");

        Tcl_Eval(pTclInterp, "package names");
        printf("%s\n", Tcl_GetString(Tcl_GetObjResult(pTclInterp)));

        Tcl_Eval(pTclInterp,"sound s -file m1.wav");
        printf("%s\n", Tcl_GetString(Tcl_GetObjResult(pTclInterp)));
        Tcl_Eval(pTclInterp,"s play -block 1");
        printf("%s\n", Tcl_GetString(Tcl_GetObjResult(pTclInterp)));
        Tcl_DeleteInterp(pTclInterp);
        return 0;

echo.sj wrote:
>         Tcl_Interp *pTclInterp = Tcl_CreateInterp();
>         if(!pTclInterp)
>         {
>                 printf("Tcl Interpreter could not be created.\n");
>                 return 0;
>         }

You forgot:

        if (Tcl_Init(pInterp) != TCL_OK) {
            printf("Tcl Interpreter could not be initialized.\n");
            return 0;
        }

>         Tcl_Eval(pTclInterp," puts \"Hello ,world !\"");

>    Tcl_Eval(pTclInterp, "package names");
>    printf("%s\n", Tcl_GetString(Tcl_GetObjResult(pTclInterp)));

That could be simpler, using Tcl_GetStringResult().

Since Tcl has no built-in [sound] command, I suspect it is here
that you want to call Tcl_PkgRequire().

On May 29, 1:46 am, Don Porter <dgpor@verizon.net> wrote:

> echo.sj wrote:
> >         Tcl_Interp *pTclInterp = Tcl_CreateInterp();
> >         if(!pTclInterp)
> >         {
> >                 printf("Tcl Interpreter could not be created.\n");
> >                 return 0;
> >         }

> You forgot:

>         if (Tcl_Init(pInterp) != TCL_OK) {
>             printf("Tcl Interpreter could not be initialized.\n");
>             return 0;
>         }

Thanks for your help. When I added Tcl_Init to init the pInterp , I
found that the tcl_Interp were not initialized. and I involked
"Tcl_FindExecutable(argv[0]);" before I created the Tcl_Interp , then
it executed successfully.

But if I run the program in a machine without tcl environment, it
failed with error msg " TCL Interpreter could not be initialized".
What can I do to build such a program to run without TCL environment.
Thanks in advance.

echo.sj wrote:
> But if I run the program in a machine without tcl environment, it
> failed with error msg " TCL Interpreter could not be initialized".
> What can I do to build such a program to run without TCL environment.

You want to google for "Starkit" and get help from the experts on
deployment with that technique.

Another option is to use the tools in the Tcl Developer Kit from
ActiveState.

--
| Don Porter          Mathematical and Computational Sciences Division |
| donald.por@nist.gov             Information Technology Laboratory |
| http://math.nist.gov/~DPorter/                                  NIST |
|______________________________________________________________________|

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc