-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcstring.blt
executable file
·48 lines (39 loc) · 1.24 KB
/
cstring.blt
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
import "string.h" with "C" as cstring;
import "string" with "Python" as pstring;
import range;
example_copy_data {
cstring.memcpy( __dest=here,
__src=there,
__n=blah );
// TODO determine what to do if the c file didn't include the argument names
}
strlen = extern "C" (const char* str)
=> (word count) {{strlen}};
memcpy = extern "C" (const byte* dest, const byte* src, uint32 size)
=> (int32 count) {{memcpy}};
template(typename T)
class parray
{
init;
del;
append(T item);
}
// $ means external object... not sure what it is... the language handler will
// deal with the object and we'll keep it as a pointer basically, but with some type
// saftey
$PARRAY parray::data;
parray::init
: data( self.setup )
{
}
// like with c, you must add the python library in the command line to compile...
// compiler must make sure del and init are never private
parray::del
{
delete data;
}
// second form of extern syntax if you want to add some variables...
parray::append(dint item)
= extern "Python" ($PARRAY array=self.data, int item=item) {{ array.append(item) }}
// no using self if called from init... maybe
parray::setup = extern "Python" => ($PARRAY) {{ [] }}