免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1295 | 回复: 2
打印 上一主题 下一主题

[其他] [tcl] How to Use Tcl and C Together [复制链接]

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-18 17:48 |只看该作者 |倒序浏览
0. Bare-Fisted Coding

  1. $ cc -c example.c -o example.o
  2. ld -shared -expect_unresolved \
  3.     -o mycommand.so example.o
  4. $ cat example.c
  5. #include <tcl.h>

  6. int MyCommand(ClientData clientData,
  7.               Tcl_Interp *interp,
  8.               int argc, char *argv[])
  9. {
  10.     char *datum, temp;

  11.     datum = "";
  12.     if (argc >= 2) {
  13.         datum = argv[1];
  14.         if (strlen(datum) > 3) {
  15.         temp = datum[0];
  16.         datum[0] = datum[1];
  17.         datum[1] = temp;
  18.         }
  19.     }
  20.     Tcl_SetResult(interp, datum, NULL);
  21.     return TCL_OK;
  22. }

  23. int Mycommand_Init(Tcl_Interp *interp)
  24. {
  25.     if (Tcl_InitStubs(interp, "8.1", 0) == NULL) {
  26.     return TCL_ERROR;
  27.     }
  28.     Tcl_CreateCommand(interp, "mycommand", MyCommand,
  29.     (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
  30.     return TCL_OK;
  31. }
复制代码
1. SWIG tcl
    http://www.swig.org/translations/chinese/index.html
2.
    http://wiki.tcl.tk/ffidl
3.
    https://www.tcl.tk/community/tcl ... r-critcl/critcl.pdf
  1. package require critcl
  2. namespace import critcl::*

  3. cproc cube {int x} int {
  4.     return x * x * x;
  5. }

  6. proc report number {
  7.     puts "The cube of $number is [cube $number]."
  8. }
复制代码
ref:
    http://collaboration.cmc.ec.gc.c ... 212/laird/laird.htm
    https://www.tcl.tk/community/tcl ... r-critcl/critcl.pdf

论坛徽章:
16
CU十二周年纪念徽章
日期:2013-10-24 15:41:3415-16赛季CBA联赛之广东
日期:2015-12-23 21:21:55青铜圣斗士
日期:2015-12-05 10:35:30黄金圣斗士
日期:2015-11-26 20:42:16神斗士
日期:2015-11-19 12:47:50每日论坛发贴之星
日期:2015-11-18 06:20:00程序设计版块每日发帖之星
日期:2015-11-18 06:20:002015亚冠之城南
日期:2015-11-10 19:10:492015亚冠之萨济拖拉机
日期:2015-10-28 18:47:282015亚冠之柏太阳神
日期:2015-08-30 17:21:492015亚冠之山东鲁能
日期:2015-07-07 18:48:39摩羯座
日期:2014-08-29 23:01:42
2 [报告]
发表于 2016-02-22 11:07 |只看该作者
Simplified Wrapper and Interface Generator
神器啊

论坛徽章:
93
2015年辞旧岁徽章
日期:2019-10-10 10:51:15CU大牛徽章
日期:2014-02-21 14:21:56CU十二周年纪念徽章
日期:2020-10-15 16:55:55CU大牛徽章
日期:2014-02-21 14:22:07羊年新春福章
日期:2019-10-10 10:51:39CU大牛徽章
日期:2019-10-10 10:55:38季节之章:春
日期:2020-10-15 16:57:40ChinaUnix元老
日期:2019-10-10 10:54:42季节之章:冬
日期:2019-10-10 10:57:17CU大牛徽章
日期:2014-02-21 14:22:52CU大牛徽章
日期:2014-03-13 10:40:30CU大牛徽章
日期:2014-02-21 14:23:15
3 [报告]
发表于 2016-02-22 11:22 |只看该作者
膜拜一下神器!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP