Changes To Examples

Changes to "Examples" between 2014-06-23 02:57:17 and 2014-06-24 04:28:41

1
2
3
4
5
6
7
8
9
10
11
12
13
14


15
16
17




















18
19

























1
2
3
4
5
6
7
8
9
10
11
12


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63












-
-
+
+



+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
tcc4tcl Examples
================

Simple Example
--------------
    #! /usr/bin/env tclsh
    
    package require tcc4tcl
    set handle [tcc4tcl::new]
    $handle cproc add {int a int b} long { return(a+b); }
    puts [add 1 2]

More Complete Example
---------------------
Example 1: mkdir
----------------
    #! /usr/bin/env tclsh
    
    package require tcc4tcl
    
    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);
    }

Example 2: curl
---------------
    #! /usr/bin/env tclsh
    
    package require tcc4tcl
    
    set handle [tcc4tcl::new]
    ...in progress...
    
    $handle ccode {
    #include <stdint.h>
    #include <curl/curl.h>
    }
    $handle cwrap curl_version {} vstring
    $handle cproc curl_fetch {char* url} ok {
            void *handle;
    
            handle = curl_easy_init();
            if (!handle) {
                    return(TCL_ERROR);
            }
    
            curl_easy_setopt(handle, CURLOPT_URL, url);
            curl_easy_perform(handle);
    
            return(TCL_OK);
    }
    $handle add_library_path /usr/lib64
    $handle add_include_path /usr/include
    $handle add_library curl
    $handle go
    
    curl_fetch http://rkeene.org/