- The added line is THIS COLOR.
- The deleted line is THIS COLOR.
CritclはTclのソースにCなどのコードを埋め込んで、"on the fly"にコンパイルする拡張です。PerlでいうところのinlineCです。
CritclはTclのソースにCなどのコードを埋め込んで、"on the fly"にコンパイルする拡張です。PerlでいうところのinlineCです。速くなると思います。ベンチマークも取ってみたいと思います。
***基本的な使い方 [#cfc70bd2]
-gccがインストールされていないといけません。
-コンパイルされたdll/soは~/.critclにキャッシュされます。
package require critcl
critcl::cproc add {int a int b} int {
return a + b; /* this is C code */
}
critcl::cproc addf {double a double b} double {
return a + b; /* this is C code */
}
char型、配列、ポインタはこの方法では引数に渡せない(?)ようです。
***Cのヘッダファイルなどを埋め込み [#ca1838fd]
package require critcl
critcl::ccode {
#include <stdio.h>
#include <stdlib.h>
}
critcl::cproc testput {} void {
char *str = malloc(sizeof(char)*100);
int i;
for (i=0; i<100; i++)
sprintf(str+i, "%d", i%10);
for (i=0; i<10; i++)
printf("%c\n", str[i]);
free(str);
return;
}
*** Cのファイルとリンク[#j1f0bbe8]
counter.h
#ifndef _DEF_H_COUNTER
#define _DEF_H_COUNTER
extern int incrCount();
extern int CountVal;
#endif
counter.c
#include "counter.h"
int CountVal = 0;
int incrCount()
{
return ++CountVal;
}
test.tcl
package require critcl
critcl::cheaders counter.h
critcl::csources counter.c
critcl::ccode {
#include <stdio.h>
#include <stdlib.h>
#include "counter.h"
}
critcl::cproc countUp {} void {
int i;
for (i=0; i<10; i++) {
incrCount();
printf("%d\n", CountVal);
}
return;
}
***ライブラリの作成 [#xae0c10d]
critclではライブラリを作ることもできます。~
test.tcl
package require critcl
critcl::cproc add {int a int b} int {
return a + b; /* this is C code */
}
critcl::cproc addf {double a double b} double {
return a + b; /* this is C code */
}
これをライブラリにするには、
tclkit critcl.kit -lib test.tcl
とすると、test.dllが作成されます。これを使うには普通にtclshで
load test.dll
などとしてやればいいです。Win,Mac,UNIXでMakefileを書き分けたりせずに簡単にコンパイルできるのが楽でいいと思いましたです。
***ライブラリの作成(パッケージ) [#d2731e91]
パッケージにすることもできます。
***コメントをどーぞ [#v624aabe]
#comment
----
[[CategoryTclTk]]
HTML convert time: 0.004 sec.