View · Search · Index
No registered users in community xowiki
in last 10 minutes

Re: [Xotcl] instprocs in C

From: Aamer Akhter <aakhter_at_gmail.com>
Date: Sat, 18 Feb 2006 13:41:24 -0500

On 2/16/06, Gustaf Neumann <neumann_at_wu-wien.ac.at> wrote:
> Aamer Akhter schrieb:
>
> >Critcl allows us to easily create tcl callable C procs. Is there
> >something similar avaliable for xotcl?
> >
> >Is there any C api documentation?
> >
> >
> There is as well a simpler way, defining e.g. a cinstproc similar to the
> cproc:
>
> ===============================================================
> lappend auto_path .
> package require critcl
>
> Class instproc cinstproc {name arglist returntype body} {
> critcl::cproc $name $arglist $returntype $body
> catch {$name} ;# there must be a better way forcing the compile!
> rename $name ::xotcl::classes[self]::$name
> }
> ===============================================================
>
> now one can define a Class and a cinstproc and use it.
>
> ===============================================================
> Class C
> C cinstproc triple {int i} int {
> return i * 3; /* this is C code */
> }
>
> C c1
> puts "three times 123 is [c1 triple 123]"
> ===============================================================
>
> this might be already sufficient for you. Two things should be done
> more beautiful:

Thank-you, this certainly gives ideas. I'll have to play around with
it and look at the existing code sent out earlier to understand the
API a bit better.

>
> a) the compilation in criticl seems to be forced through unknown.
> my approach with the catch is rather crude. but i am sure, there must
> be an option.

I have been doing the catch/compile myself- don't know if there is
another way for runtime use. Personnally, it comes in usefull as it
allows for doing falback to tcl-only versions.


>
> b) It would be nice to generate the command in the right namespace.
> i found as well no nice approach to do this.

I've been using the critcl::ccommand inside a namespace eval to place
the command in the right namespace. That appears to work. eg:

package require critcl;

namespace eval ::ip {

critcl::ccode {
#include <stdlib.h>
....
}

critcl::ccommand prefixToNativec {clientData interp objc objv} {
    int elemLen, maskLen, ipLen, mask;
        int rval,convertListc,i;
        Tcl_Obj **convertListv;
        Tcl_Obj *listPtr,*returnPtr, *addrList;
        char *stringIP, *slashPos, *stringMask;
        char v4HEX[11];
        
        uint32_t inaddr;
 ....
 }

}; #namespace eval
>
> Aamer, if you have some experience here, feedback would be welcome,
>
> -gustaf
>
> >
> >
> >--
> >Aamer Akhter / aakhter_at_gmail.com
> >
> >_______________________________________________
> >Xotcl mailing list
> >Xotcl_at_alice.wu-wien.ac.at
> >http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
> >
> >
>
>


--
Aamer Akhter / aakhter_at_gmail.com