Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Please try to turn C structures into Tcl objects.

Posted by lanjun (lanjun), 21 August 2006
today,i try to turn a C structure into Tcl object.but failed. who can help me to do that?thanks!!!
the simple C file which contains struct type is showed following.
file: test.c
/*test.c*/
#include <stdio.h>
struct s {
 int a;
 int b;
};
void print(struct s s1)
{
   printf("begain to invoking print function:\n");
   s1.a=3;
   s1.b=4;
   printf("end of invoking print function.\n");
}

void main()
{
   print(s1);
}


ok,above is all.
As above procedure,i want to use tcl language to invoke the print function which is defined in test.c file. how can i do?please tell me.whenever,i always expect your answer or good idea.  thanks for your view again.



Posted by admin (Graham Ellis), 21 August 2006
Hi, Lanjun.   How did you get on with the freewrap issue?  Long time no here  

Chapter 34 of John Ousterhout's "Tcl and the Tk toolkit" book covers the accessing of Tcl variables in C, and I think that's probably the way to go - the variables to need to be set up in Tcl's symbol table to be accessed from there, whereas C does not have a run time symbol table.    Have a look also as the sample programs in our Using Tcl from C module.

Posted by lanjun (lanjun), 22 August 2006
hi,Mr. Graham Ellis,
i'm so amazed you still remembered my last topic. but it's so sadly that i can't pass the  wall. becuase it refered SWIG tool which is used to binding tcl and ANSI C. So i have to break it off, and continue to study SWIG(Simplified Wrapper and Interface Generator) tool. can you use it?
but it's easy to wrap a tcl/tk procedure to a executable file, and you can use it to run different platform without installing tcl/tk script.
i have read the chapter 34 of John Ousterhout's "Tcl and the Tk tookit" book.but it's too complex to understand without a usefull sample. and the syntax is also look like a little difficult. so i still don't know how to do for above C program.
hehe,of course,if you have time, could you help me to turn above simple c program into a tcl application? i will understand its elements quickly. thank you very much!!!

Posted by admin (Graham Ellis), 22 August 2006
Forums such as this are ideal for answering specific questions and helping out with pointers to other resources where an issue gets longer or more complex.   They're less good for "write me a program" type questions, where what you really need to find is a contractor, or "teach me a complete topic" questions, where a book or a training course is better suited.

With your requirement, I felt from the start that it was rather too big a topic to cover reasonably on a thread here - thus, I pointed you at what I feel is the most appropriate resource.  If you feel that resource is too advanced, then my next suggestion would be that you find someone who can take you through the C and Tcl issues face to face - it's something that I could do under our extra scheme (I don't think you need a full course); if that's not geographically convenient, then perhaps there's someone else in your own neck of the woods?

You comment about my remembering your previous post.   I use the computer to help my memory   ... just as you like to have answers, so do I, and I encourage people to come back and complete threads / tell us the punch line - that way, they're helping other later visitors to these pages. Where  I've answered a thread and not heard further - not even a "Thank You" - I tend to take note and to lessen the amount of time I can be bothered to spend helping that poster later on.  Funny thing - it's never our customers who fail to show what in my culture is an elemental politeness - it's always the people who are looking for lots of free support.

Posted by lanjun (lanjun), 22 August 2006
i regret to you for my impolite question.
i'm sorry for that........

Posted by admin (Graham Ellis), 22 August 2006
No doubt you have a different culture where you're from ... don't worry about it!

Posted by lanjun (lanjun), 7 September 2006
this question have been resolved yesterday. that's make me felt more confident about studying TCL language.
 so, i will shared the methods to every friends. hope it's a little helpfull for your.
 As Brent B. Welch in "Practical Programming in Tcl & Tk, Third Edition" said: "There are two ways to get started writing C code for Tcl applications. The easiest way is to write an extension that just adds some new commands to a standard Tcl shell like tclsh or wish. With this approach the Tcl shell creates a basic framework for you, and your C code just extends this framework with new commands. Tcl supports dynamic loading, so you can compile your extension as a shared library (i.e., DLL) and load it into a running Tcl shell. This is the easiest approach because the Tcl shell handles the details of startup and shutdown, and it provides an interactive console to enter Tcl commands. In the case of wish, it also provides the framework for a graphical user interface. Finally, a loadable extension can be shared easily with other Tcl users."


that's true, i have tried to test a lot of methods to wrap a c  program to a dynamic library. i found the easiest and  fastest methods is SWIG tool. if you have interesting, you can view following web:
http://www.swig.org/

As above sample by myself:
you can just write a SWIG interface file, then you can get a dynamic library which used to tcl load command. if you have interesting, you can try.

SWIG interface  file:
/*test.i*/
%module test
%{
#include test.h    /*defined struct here*/
%}

extern void print(struct s s1)
extern void main()

ok,then implement SWIG command, and you will get a test.so file that can use to be loaded by tcl language.
ok,that's all. good luck for you!!



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2021: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho