Critcl allows us to easily create tcl callable C procs. Is there something similar avaliable for xotcl?
Is there any C api documentation?
-- Aamer Akhter / aakhter@gmail.com
It is pretty straightforward to extend XOTcl with C functions. Almost the same as extending Tcl. See the XOTcl extensions XOTclGdbm, XOTclSdbm, in the XOTcl distribution as examples. Unfortunately, there is no documentation of the C API yet, only those examples
Uwe
Aamer Akhter wrote:
Critcl allows us to easily create tcl callable C procs. Is there something similar avaliable for xotcl?
Is there any C api documentation?
-- Aamer Akhter / aakhter@gmail.com
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
Hi all,
i used the autoname instproc to create object instance names and was surprised that autonames can conflict.
Basically i have two objects of the same class, which both get rows from a database and create objects for each row:
Something like this:
PM instproc dbRead {program_id} { # some things ommited my set tracks "" set tracks [::MOD select list program_tracks {track_id} program_id $program_id] foreach t $tracks { set m [::wings::model::TrackModel [my autoname TrackM]] $m dbRead $t my lappend tracks $m } }
After i create two objects of this class, i see the TrackM autonames used by both objects starting from 0, basically the second object overwrites my autonamed objects from the first one.
I fixed it by adding:
my instproc autoname {args} { set name [next] while {[llength [info commands $name]]} {set name [next]} return $name }
to the class, but wondered if this is expected behaviour of autonames.
Michael
Michael, use
foreach t $tracks { set m [::wings::model::TrackModel new] $m dbRead $t my lappend tracks $m }
or shorter:
foreach t $tracks { my lappend tracks [::wings::model::TrackModel new -dbRead $r] }
Michael Schlenker schrieb:
Hi all,
i used the autoname instproc to create object instance names and was surprised that autonames can conflict.
Basically i have two objects of the same class, which both get rows from a database and create objects for each row:
Something like this:
PM instproc dbRead {program_id} { # some things ommited my set tracks "" set tracks [::MOD select list program_tracks {track_id} program_id $program_id] foreach t $tracks { set m [::wings::model::TrackModel [my autoname TrackM]] $m dbRead $t my lappend tracks $m } }
After i create two objects of this class, i see the TrackM autonames used by both objects starting from 0, basically the second object overwrites my autonamed objects from the first one.
I fixed it by adding:
my instproc autoname {args} { set name [next] while {[llength [info commands $name]]} {set name [next]} return $name }
to the class, but wondered if this is expected behaviour of autonames.
Michael
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
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:
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.
b) It would be nice to generate the command in the right namespace. i found as well no nice approach to do this.
Aamer, if you have some experience here, feedback would be welcome,
-gustaf
-- Aamer Akhter / aakhter@gmail.com
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
On 2/16/06, Gustaf Neumann neumann@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@gmail.com
Xotcl mailing list Xotcl@alice.wu-wien.ac.at http://alice.wu-wien.ac.at/mailman/listinfo/xotcl
-- Aamer Akhter / aakhter@gmail.com