Mercurial > projects > dmdscript-tango
comparison dmdscript_tango/dnative.d @ 0:55c2951c07be
initial, files origin, premoved tree
author | saaadel |
---|---|
date | Sun, 24 Jan 2010 12:34:47 +0200 |
parents | |
children | 8363a4bf6a8f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:55c2951c07be |
---|---|
1 | |
2 /* Digital Mars DMDScript source code. | |
3 * Copyright (c) 2000-2002 by Chromium Communications | |
4 * D version Copyright (c) 2004-2005 by Digital Mars | |
5 * All Rights Reserved | |
6 * written by Walter Bright | |
7 * www.digitalmars.com | |
8 * Use at your own risk. There is no warranty, express or implied. | |
9 * License for redistribution is by the GNU General Public License in gpl.txt. | |
10 * | |
11 * A binary, non-exclusive license for commercial use can be | |
12 * purchased from www.digitalmars.com/dscript/buy.html. | |
13 * | |
14 * DMDScript is implemented in the D Programming Language, | |
15 * www.digitalmars.com/d/ | |
16 * | |
17 * For a C++ implementation of DMDScript, including COM support, | |
18 * see www.digitalmars.com/dscript/cppscript.html. | |
19 */ | |
20 | |
21 | |
22 module dmdscript.dnative; | |
23 | |
24 import dmdscript.script; | |
25 import dmdscript.dobject; | |
26 import dmdscript.dfunction; | |
27 import dmdscript.value; | |
28 | |
29 /******************* DnativeFunction ****************************/ | |
30 | |
31 alias void *function(Dobject pthis, CallContext *cc, Dobject othis, Value* ret, Value[] arglist) PCall; | |
32 | |
33 struct NativeFunctionData | |
34 { | |
35 d_string* string; | |
36 PCall pcall; | |
37 d_uint32 length; | |
38 } | |
39 | |
40 class DnativeFunction : Dfunction | |
41 { | |
42 PCall pcall; | |
43 | |
44 this(PCall func, tchar[] name, d_uint32 length) | |
45 { | |
46 super(length); | |
47 this.name = name; | |
48 pcall = func; | |
49 } | |
50 | |
51 this(PCall func, tchar[] name, d_uint32 length, Dobject o) | |
52 { | |
53 super(length, o); | |
54 this.name = name; | |
55 pcall = func; | |
56 } | |
57 | |
58 void* Call(CallContext *cc, Dobject othis, Value* ret, Value[] arglist) | |
59 { | |
60 return (*pcall)(this, cc, othis, ret, arglist); | |
61 } | |
62 | |
63 /********************************* | |
64 * Initalize table of native functions designed | |
65 * to go in as properties of o. | |
66 */ | |
67 | |
68 static void init(Dobject o, NativeFunctionData[] nfd, uint attributes) | |
69 { | |
70 Dobject f = Dfunction.getPrototype(); | |
71 | |
72 for (size_t i = 0; i < nfd.length; i++) | |
73 { NativeFunctionData* n = &nfd[i]; | |
74 | |
75 o.Put(*n.string, | |
76 new DnativeFunction(n.pcall, *n.string, n.length, f), | |
77 attributes); | |
78 } | |
79 } | |
80 } |