Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to call a C function from a TCL script?
Hello, I'm new to TCL so this will probably be easy for the experts
out there. I would like to call a C function from my TCL script, can
anyone point me in the right direction where I can learn how to to
this?

thanks,
joe

Report this thread to moderator Post Follow-up to this message
Old Post
joe
10-20-04 09:07 PM


Re: How to call a C function from a TCL script?
"joe" <jjlindula@hotmail.com> wrote in message
news:880397ee.0410201001.505400c1@posting.google.com...
> Hello, I'm new to TCL so this will probably be easy for the experts
> out there. I would like to call a C function from my TCL script, can
> anyone point me in the right direction where I can learn how to to
> this?

There are a number of ways to accomplish that (or something similar to
that); the one that comes closest to what you have in mind is probably to
write a Tcl extension.  If you choose to go that route, you'll need to learn
the basics of the Tcl C API.  Some resources to help you do that:

*This chapter from Brent Welch's _Practical Programming in Tcl and Tk_ gives
a good overview of the API.
http://www.beedub.com/book/3rd/Cprogint.pdf

*Matti Kärki's sample extension is an excellent example of a minimal
extension, complete with directions on how to compile it:
http://koti.welho.com/mkarki2/files/test.c.txt

Other, easier options include creating an executable of your C code and
communicating with it through a pipe (see the [open] command manpage) or a
socket (see the [socket] manpage).  I assume it's also possible to create a
DLL of your C code and call it through ffidl; other newsgroup readers can
provide more on that option than I can.

If you aren't already familiar with the wiki, it's probably worth searching
around there for other possible solutions:
http://mini.net/tcl/

Regards,
Aric



Report this thread to moderator Post Follow-up to this message
Old Post
Aric Bills
10-20-04 09:07 PM


Re: How to call a C function from a TCL script?
In article <880397ee.0410201001.505400c1@posting.google.com>,
joe <jjlindula@hotmail.com> wrote:
>Hello, I'm new to TCL so this will probably be easy for the experts
>out there. I would like to call a C function from my TCL script, can
>anyone point me in the right direction where I can learn how to to
>this?

Report this thread to moderator Post Follow-up to this message
Old Post
Cameron Laird
10-20-04 09:07 PM


Re: How to call a C function from a TCL script?
joe wrote:

> Hello, I'm new to TCL so this will probably be easy for the experts
> out there. I would like to call a C function from my TCL script, can
> anyone point me in the right direction where I can learn how to to
> this?

Depends...

You want to call a C function, but in what context?  Do you wish to
simply call an extant complex C function which you do not wish to port
to tcl?  Does it involve large amounts of data (e.g. you want to process
a large data set that you've stored in a tcl variable)?  Are you going
to call it infrequently, or repeatedly?  Are you intending to trigger an
event in another program that runs for a long time?

The best way to integrate an external function depends a lot on context.

If you are looking to process a large data set, it might be best to
convert your C code into a Tcl extension.

If you have an existing program that sits around and you want to trigger
an event, you might attempt to send it a message using inter-process
communication channels (e.g. sockets, COM, DDE, X-Window system
messages).  Some sort of client/server model.   These are surprisingly
trivial in Tcl, and if you give some idea of your environment, someone
should be able to point you to example code.

If it's an infrequent call to an OS-specific facility, you might
consider wrapping your C function in a simple command-line utility and
[exec] or [open] it (I've done this a bit with collecting Windows
performance counter data, including server apps on multiple computers
with a client that connects via socket to plot multiple-machine load
statistics).

What is the context of your existing code?

--
MKS

Report this thread to moderator Post Follow-up to this message
Old Post
Melissa Schrumpf
10-21-04 08:59 AM


Re: How to call a C function from a TCL script?
In article <m_schrumpf_at_yahoo_com_NOT-AEB02E.23364820102004@comcast.dca.gi
ganews.com>,
Melissa Schrumpf  <m_schrumpf_at_yahoo_com_NOT@microsoft.com> wrote:
>joe wrote:
> 
>
>Depends...
>
>You want to call a C function, but in what context?  Do you wish to
>simply call an extant complex C function which you do not wish to port
>to tcl?  Does it involve large amounts of data (e.g. you want to process
>a large data set that you've stored in a tcl variable)?  Are you going
>to call it infrequently, or repeatedly?  Are you intending to trigger an
>event in another program that runs for a long time?
>
>The best way to integrate an external function depends a lot on context.
>
>If you are looking to process a large data set, it might be best to
>convert your C code into a Tcl extension.
>
>If you have an existing program that sits around and you want to trigger
>an event, you might attempt to send it a message using inter-process
>communication channels (e.g. sockets, COM, DDE, X-Window system
>messages).  Some sort of client/server model.   These are surprisingly
>trivial in Tcl, and if you give some idea of your environment, someone
>should be able to point you to example code.
>
>If it's an infrequent call to an OS-specific facility, you might
>consider wrapping your C function in a simple command-line utility and
>[exec] or [open] it (I've done this a bit with collecting Windows
>performance counter data, including server apps on multiple computers
>with a client that connects via socket to plot multiple-machine load
>statistics).
>
>What is the context of your existing code?

Report this thread to moderator Post Follow-up to this message
Old Post
Cameron Laird
10-21-04 01:57 PM


Re: How to call a C function from a TCL script?
claird@lairds.us (Cameron Laird) wrote in message news:<75ik42-7l1.ln1@lairds.us>...
> In article <m_schrumpf_at_yahoo_com_NOT-AEB02E.23364820102004@comcast.dca.
giganews.com>,
> Melissa Schrumpf  <m_schrumpf_at_yahoo_com_NOT@microsoft.com> wrote: 
> 			.
> 			.
> 			.
> On-target.  And don't forget, Melissa, that different
> people think of "a C function" as alternatively its
> source representation (for them, critcl might even be
> the beset choice) or a compiled object image (which
> might better suggest ffidl and friends).  You're ab-
> solutely right:  while the question looks simple, a
> correct answer requires considerable analysis.

Hello, I already have a script but know I would like to call a C
function that is located in another file, say for example "burn.c"
which burns executable boot code into flash memory. Here is my
function:
void burn()
{
unsigned int *pBurnAdd[6];
unsigned int i;

pINTMEM = (unsigned int *) INT_MEM;
pNOVRAM = (unsigned int *) NOVAD;

MemLen = 8540;

//pINTMEM++;
for (i=0; i<MemLen; i++)
{
loaderData = *pINTMEM;
*pNOVRAM++ = loaderData;
*pNOVRAM++ = loaderData >> 8;
*pNOVRAM++ = loaderData >> 16;
*pNOVRAM++ = loaderData >> 24;
*pINTMEM++;
}

//burn sequence
pBurnAdd[0] = (unsigned int *) 0x10304E38;
pBurnAdd[1] = (unsigned int *) 0x1030B1C7;
pBurnAdd[2] = (unsigned int *) 0x103083E0;
pBurnAdd[3] = (unsigned int *) 0x10307C1F;
pBurnAdd[4] = (unsigned int *) 0x1030703F;
pBurnAdd[5] = (unsigned int *) 0x10304C63;

}

The .tcl file and the burn function are in the same directory. Could I
include some kind of label that I could insert in the function like
START_BURN and STOP_BURN and then reference them in my .tcl script?

thanks for all your suggestions,
joe

Report this thread to moderator Post Follow-up to this message
Old Post
joe
10-22-04 01:57 AM


Re: How to call a C function from a TCL script?
In article <880397ee.0410211206.5776decb@posting.google.com>,
joe <jjlindula@hotmail.com> wrote:

Report this thread to moderator Post Follow-up to this message
Old Post
Cameron Laird
10-22-04 01:57 AM


Re: How to call a C function from a TCL script?
claird@lairds.us (Cameron Laird) wrote in message news:<8ukl42-9kc.ln1@lairds.us>...
> In article <880397ee.0410211206.5776decb@posting.google.com>,
> joe <jjlindula@hotmail.com> wrote:
> 			.
> 			.
> 			. 
> 			.
> 			.
> 			.
> Interesting!  What you want certainly can be achieved,
> and might, in fact, make a provocative demonstration of
> critcl.  Where are INT_MEM and NOVAD defined?
>
> In principle, the solution is only a couple of minutes
> away from someone experienced in Tcl.  It might take a
> while to explain, though ...  Please start with my
> question above.

Hello, INT_MEM and NOVAD are just define statements and are equal to
some 32-bit number, I could easily insert the actual value instead of
using a #define statement.

thanks,
joe

Report this thread to moderator Post Follow-up to this message
Old Post
joe
10-25-04 09:02 PM


Re: How to call a C function from a TCL script?
In article <880397ee.0410250546.287b9623@posting.google.com>,
joe <jjlindula@hotmail.com> wrote:
>claird@lairds.us (Cameron Laird) wrote in message
>news:<8ukl42-9kc.ln1@lairds.us>... 
>
>Hello, INT_MEM and NOVAD are just define statements and are equal to
>some 32-bit number, I could easily insert the actual value instead of
>using a #define statement.

Report this thread to moderator Post Follow-up to this message
Old Post
Cameron Laird
10-25-04 09:02 PM


Re: How to call a C function from a TCL script?
On Wed, 20 Oct 2004, joe wrote:
> Hello, I'm new to TCL so this will probably be easy for the experts
> out there. I would like to call a C function from my TCL script, can
> anyone point me in the right direction where I can learn how to to
> this?

MkTclApp is your friend.

http://www.hwaci.com/sw/mktclapp/index.html

Simple interface, and D.R. Hipp has given the community a number of ""
tools.  (MkTclApp, SQLite, various widgets ... )

(just a happy customer ... I'm not Hipp).

Report this thread to moderator Post Follow-up to this message
Old Post
spam@controlq.com
10-27-04 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

Tcl archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:29 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.