Overview
Artifact ID: | 3abed24b97a1099bbf57c0bd52a64bf997120cb1 |
---|---|
Page Name: | Documentation |
Date: | 2014-06-17 16:47:19 |
Original User: | rkeene |
Mimetype: | text/x-markdown |
Parent: | 4587d632ddad00761c6f9fe54913b7cee5ce8836 (diff) |
Next | 6ce701f58b9fb5058f881fff69edc393782d11f1 |
Content
Manual Page
package require tcc4tcl
tcc4tcl::cproc
Creates a Tcl procedure that calls C code.
Synopsis:
tcc4tcl::cproc <procName> <argList> <returnType> <code>
<procName>
is the name of the Tcl procedure to create<argList>
is a list of arguments and their types for the C function;- The list is in the format of: type1 name1 type2 name2 ... typeN nameN
- The supported types are:
- Tcl_Interp*: Must be first argument, will be the interpreter and the user will not need to pass this parameter
- int
- long
- float
- double
- char*
- Tcl_Obj*: Passes the Tcl object in unchanged
- void*
<returnType>
is the return type for the C function- The supported types are:
- void: No return value
- ok: Return TCL_OK or TCL_ERROR
- int
- long
- float
- double
- char*: TCL_STATIC string (immutable from C -- use this for constants)
- string, dstring: TCL_DYNAMIC string (allocated from Tcl_Alloc, will be managed by Tcl)
- vstring: TCL_VOLATILE string (mutable from C, will be copied be Tcl -- use this for local variables)
- default: Tcl_Obj*, a Tcl Object
- The supported types are:
<code>
is the C code that comprises the function
Examples:
- Create a Tcl procedure called "add" which accepts 2 integers (a, b) and returns a long:
tcc4tcl::cproc add {int a int b} long { return(a+b); }
- Create a Tcl procedure called "mkdir" which accepts a Tcl_Obj* and returns a return code:
tcc4tcl::cproc mkdir {Tcl_Interp* interp char* dir} ok { int mkdir_ret; mkdir_ret = mkdir(dir); if (mkdir_ret != 0) { Tcl_SetObjResult(interp, Tcl_NewStringObj("failed", -1)); return(TCL_ERROR); }; return(TCL_OK); }