-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.html
More file actions
executable file
·570 lines (462 loc) · 21.2 KB
/
src.html
File metadata and controls
executable file
·570 lines (462 loc) · 21.2 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>d'Arc 0.2.0</title>
<style type="text/css"><!--
body { font-family: "Century Gothic", Verdana, Helvetica, Arial, sans-serif;
text-align: justify;
margin: 0;
background-color: #fffce0; }
a { color: #c25036;
text-decoration: none; }
a:visited { color: brown; }
a:hover { color: orange; }
img.head { margin: 0px 10px 10px 0px; }
div.body { padding: 4em 5em 1em 5em;
text-align: justify;
}
div.panel { background-color: white;
border-radius: 2em;
-moz-border-radius: 2em;
border: 2px solid navy;
margin: 2em;
padding: 2em;
}
pre.code-index,
pre.code,
pre
{ background-color: #f4eca8; /* #e2d090; */ /* #fff8d2; */
border: 2px solid #fcb000; /* #f4eac8; */
padding: 1em;
border-bottom-left-radius: 1em;
-moz-border-radius-bottomleft: 1em;
border-top-right-radius: 1em;
-moz-border-radius-topright: 1em;
overflow: hidden; scrollbar: auto;
}
pre.codelast-index,
pre.codelast
{ background-color: #f4eca8; /* #e2d090; */ /* #fff8d2; */
border: 2px solid #fcb000; /* #f4eac8; */
padding: 1em;
border-bottom-left-radius: 1em;
-moz-border-radius-bottomleft: 1em;
border-bottom-right-radius: 1.2em;
-moz-border-radius-bottomright: 1.2em;
}
pre.code,
pre { background-color: white;
border: 2px solid #f0d8c0; }
pre.codelast
{ background-color: #f0e4c4;
border: 2px solid white; }
div.head { border: 0;
border-top-left-radius: 20px 7px;
-moz-border-radius-topleft: 20px 7px;
border-bottom-right-radius: 35px 30px;
-moz-border-radius-bottomright: 50px 15px;
background: url(../etc/images/darc-head-background.png) no-repeat top right;
padding: 0; margin: 0;
}
div.foot { border: 0;
border-top-left-radius: 15px;
-moz-border-radius-topleft: 15px;
border-bottom-right-radius: 15px;
-moz-border-radius-bottomright: 15px;
background: url(../etc/images/darc-head-background.png) no-repeat bottom left;
height:31px; padding: 0; margin: 0;
}
div.rightinset
{ border: 2px solid white;
margin-left: 1em;
padding: 2.5em;
background-color: #c25036;
color: #f4eca8;
float: right;
width: 40;
border-radius: 1em;
-moz-border-radius: 1em;
font-size: 1em;
text-align: justify; }
--></style>
</head>
<body>
<div class=head>
<img class=head src=../etc/images/darc-head.png>
</div>
<div class=body>
<h1>d'Arc 0.2.0</h1>
<p>This is the complete d'Arc 0.2 source</p>
<p><strong>darc.h</strong></p>
<pre><code>/**-------------------------------------------------------------------------***
*** Package : d'Arc - fast Lua sub API ***
*** File : darc.h ***
*** Description : macros for VM value and table node access, Lua & LuaJIT ***
*** Version : 0.2.0 / alpha ***
*** Requirement : Lua 5.1.4 or LuaJIT 2 beta 7 ***
*** Copyright : April 1st 2011 Henning Diedrich ***
*** Author : H. Diedrich <hd2010@eonblast.com> ***
*** License : see file LICENSE ***
*** Created : 23 Mar 2011 ***
*** Changed : 08 May 2011 ***
***-------------------------------------------------------------------------***
*** ***
*** d'Arc is a faster way to access Lua values and traverse tables in C. ***
*** It supports Lua 5.1.4 and LuaJIT 2 beta 7 and is loathable for not ***
*** using the Lua API. Please use it only if you are 18+ years old. ***
*** ***
***-------------------------------------------------------------------------***
*** ***
*** This file contains macros that allow you to write source that will ***
*** work with both the classic PUC Lua and Mike Pall's LuaJIT. ***
*** ***
***-------------------------------------------------------------------------***
( ( (
)\ ))\ )\ (
(()/((_)(((_)( )( (
((_) ) )\ _ )\(()\ )\
_| | (_)_\(_)((_)((_)
/ _` | / _ \ | '_|/ _|
\__,_| /_/ \_\|_| \__|
* devine version ----------------------------------------------------------- */
#ifdef LUA_5_1
#undef JIT_2
#elif JIT_2
#else
#error Please define either LUA_5_1 or JIT_2
#endif
/**-------------------------------------------------------------------------**\
*** ***
*** LUA 5.1.4 ***
*** ***
\**-------------------------------------------------------------------------**/
#ifdef LUA_5_1
/* Lua headers (in include/lua-5.1.4) ------------------------------------ */
#include "lobject.h"
#include "ltable.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "ldebug.h"
#include "ldo.h"
#include "lgc.h"
#include "lmem.h"
#include "lstate.h"
TValue *index2adr(lua_State *L, int idx);
/* Lua ............ see obj.h */
#define XLUA_IS_NIL(o) ttisnil(o)
#define XLUA_IS_TRUE(o) ((o)->value.b == true)
#define XLUA_IS_FALSE(o) ((o)->value.b == false)
#define XLUA_IS_BOOLEAN(o) ttisboolean(o)
#define XLUA_IS_NUMBER(o) ttisnumber(o)
#define XLUA_IS_STRING(o) ttisstring(o)
#define XLUA_IS_TABLE(o) ttistable(o)
#define XLUA_IS_FUNCTION(o) ttisfunction(o)
#define XLUA_IS_USERDATA(o) ttisuserdata(o)
#define XLUA_IS_THREAD(o) ttisthread(o)
#define XLUA_IS_LIGHTUSERDATA(o) ttislightuserdata(o)
#define XLUA_BOOLEAN(o) ((o)->value.b)
#define XLUA_NUMBER(o) (nvalue(o))
#define XLUA_STRING(o) (svalue(o))
#define XLUA_STRING_LENGTH(o) (tsvalue(o)->len)
#define XLUA_TABLE(o) (hvalue(o))
#define XLUA_NODE_KEYVAL(node) (key2tval(node))
#define XLUA_NODE_VAL(node) (gval(node))
#define XLUA_INDEX_TO_ADDRESS(L, index) index2adr(L, index)
#define index2addr(L, index) index2adr(L, index) // eliminate pitfall
/* necessary for Lua code interfacing, taken from Lua source */
/* Lua syncrasies -------------------------------------------------------- */
/* From Lua llimits.h */
// #define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
/* from luaconf.h TODO: clear up, should be superfluous */
#if INT_MAX-20 < 32760
#define LUAI_BITSINT 16
#elif INT_MAX > 2147483640L
#define LUAI_BITSINT 32
#else
#error "you must define LUA_BITSINT with number of bits in an integer"
#endif
/* max size of array part is 2^MAXBITS (excerpt from Lua ltable.c) */
#if LUAI_BITSINT > 26
#define MAXBITS 26
#else
#define MAXBITS (LUAI_BITSINT-2)
#endif
static const char ESC=27;
static const char OPN=28;
static const char CLS=29;
#define true 1
#define false 0
#endif
/**-------------------------------------------------------------------------**\
*** ***
*** LUAJIT 2 ***
*** ***
\**-------------------------------------------------------------------------**/
#ifdef JIT_2 /* ............ see lj_obj.h */
/* LuaJIT headers (in include/jit-2.0.0) --------------------------------- */
#include "lua.h"
#include "lauxlib.h"
#include "lj_obj.h"
TValue *index2adr(lua_State *L, int idx);
typedef GCtab Table;
/* LuaJIT ............ see lj_obj.h */
#define XLUA_IS_NIL(o) tvisnil(o)
#define XLUA_IS_TRUE(o) tvistrue(o)
#define XLUA_IS_FALSE(o) tvisfalse(o)
#define XLUA_IS_BOOLEAN(o) tvisbool(o)
#define XLUA_IS_NUMBER(o) tvisnumber(o)
#define XLUA_IS_STRING(o) tvisstr(o)
#define XLUA_IS_TABLE(o) tvistab(o)
#define XLUA_IS_FUNCTION(o) tvisfunc(o)
#define XLUA_IS_USERDATA(o) tvisudata(o)
#define XLUA_IS_THREAD(o) tvisthread(o)
#define XLUA_IS_LIGHTUSERDATA(o) tvislightud(o)
#define XLUA_BOOLEAN(o) (boolV(o))
#define XLUA_NUMBER(o) (numV(o))
#define XLUA_STRING(o) (strVdata(o))
#define XLUA_STRING_LENGTH(o) (strV(o)->len)
#define XLUA_TABLE(o) (tabV(o))
#define XLUA_NODE_KEYVAL(node) ((node)->key)
#define XLUA_NODE_VAL(node) ((node)->val)
#define XLUA_INDEX_TO_ADDRESS(L, index) index2adr(L, index)
#define index2addr(L, index) index2adr(L, index) // eliminate pitfall
#endif
/**-------------------------------------------------------------------------**\
*** ***
*** d'Arc ***
*** ***
\**-------------------------------------------------------------------------**/
typedef int (*foldfunc)(TValue *o, void *cargo);
int darc_traverse(const Table *t, foldfunc fold, void *cargo);
int darc_array_part (const Table *t, foldfunc func, void *cargo);
int darc_hash_part (const Table *t, foldfunc func, void *cargo);
</code></pre>
<p><strong>darc.c</strong></p>
<pre><code>/**-------------------------------------------------------------------------***
*** Package : d'Arc - fast Lua sub API ***
*** File : darc.c ***
*** Description : macros for VM value and table node access, Lua & LuaJIT ***
*** Version : 0.2.0 / alpha ***
*** Requirement : Lua 5.1.4 or LuaJIT 2 beta 7 ***
*** Copyright : April 1st 2011 Henning Diedrich ***
*** Author : H. Diedrich <hd2010@eonblast.com> ***
*** License : see file LICENSE ***
*** Created : 01 Apr 2011 ***
*** Changed : 08 May 2011 ***
***-------------------------------------------------------------------------***
*** ***
*** d'Arc is a faster way to access Lua values and traverse tables in C. ***
*** It supports Lua 5.1.4 and LuaJIT 2 beta 7 and is loathable for not ***
*** using the Lua API. Please use it only if you are 18+ years old. ***
*** ***
***-------------------------------------------------------------------------***
*** ***
*** This file contains d'Arc table traversal functions for Lua and LuaJIT: ***
*** ***
*** darc_traverse() ***
*** ***
***-------------------------------------------------------------------------***
*** ***
*** ASCII art: http://patorjk.com/software/taag/ ***
*** ***
***-------------------------------------------------------------------------***
( ( (
)\ ))\ )\ (
(()/((_)(((_)( )( (
((_) ) )\ _ )\(()\ )\
_| | (_)_\(_)((_)((_)
/ _` | / _ \ | '_|/ _|
\__,_| /_/ \_\|_| \__|
*****************************************************************************
*** ***
*** HANDLING TABLES ***
*** ***
*****************************************************************************/
#include "darc.h"
/*---------------------------------------------------------------------------*\
* A table, internally, has a hash & an array part *
\*---------------------------------------------------------------------------*/
int darc_traverse(const Table *t, foldfunc fold, void *cargo) {
int goon = darc_hash_part(t, fold, (void *)cargo);
if(!goon) return goon;
goon = darc_array_part(t, fold, cargo);
return goon;
}
/*---------------------------------------------------------------------------*\
* Traversing the array part *
\*---------------------------------------------------------------------------*/
/* This is Lua 5.1.4 specific. */
#ifdef LUA_5_1
int darc_array_part (const Table *t, foldfunc fold, void *cargo)
{
int lg;
int ttlg; /* 2^lg */
int i = 1; /* count to traverse all array keys */
for (lg=0, ttlg=1; lg<=MAXBITS; lg++, ttlg*=2) { /* for each slice */
int lim = ttlg;
if (lim > t->sizearray) {
lim = t->sizearray; /* adjust upper limit */
if (i > lim)
break; /* no more elements */
}
/* elements in range (2^(lg-1), 2^lg] */
for (; i <= lim; i++) {
TValue * v = &t->array[i-1];
if(!ttisnil(v)) {
if(!(*fold)(v, cargo)) return 0; // =: break
}
}
}
return 1; // =: continue
}
/*---------------------------------------------------------------------------*\
* Traversing the hash part *
\*---------------------------------------------------------------------------*/
/* This is Lua 5.1.4 specific. */
int darc_hash_part (const Table *t, foldfunc fold, void *cargo)
{
int i = sizenode(t);
while (i--) {
Node *node = &t->node[i];
if(!ttisnil(key2tval(node)) && !ttisnil(gval(node))) {
if(!(*fold)(key2tval(node), cargo)) return 0; // =: break
}
}
return 1; // =: continue
}
#endif
#ifdef JIT_2
/*---------------------------------------------------------------------------*\
* Traversing the array part *
\*---------------------------------------------------------------------------*/
/* This is LuaJIT 2 specific. */
int darc_array_part (const Table *t, foldfunc fold, void *cargo)
{
uint32_t i, b;
if (t->asize == 0) return 1; // =: continue
for (i = b = 0; b < LJ_MAX_ABITS; b++) {
uint32_t n, top = 2u << b;
TValue *array;
if (top >= t->asize) {
top = t->asize-1;
if (i > top)
break;
}
array = tvref(t->array);
for (n = 0; i <= top; i++) {
TValue *v = &array[i]; /* i, not i-1, as in the Lua 5.1 part */
if (!tvisnil(v)) {
if(!(*fold)(v, cargo)) return 0; // =: break
}
}
}
return 1; // =: continue
}
/*---------------------------------------------------------------------------*\
* Traversing the hash part *
\*---------------------------------------------------------------------------*/
/* This is LuaJIT 2 specific. */
int darc_hash_part (const Table *t, foldfunc fold, void *cargo)
{
uint32_t i, hmask = t->hmask;
Node *node = noderef(t->node);
for (i = 0; i <= hmask; i++) {
Node *n = &node[i];
if (!tvisnil(&n->val) && !tvisnil(&n->key)) {
if(!(*fold)((&n->val), cargo)) return 0; // =: break
}
}
return 1; // =: continue
}
#endif // < JIT
/*****************************************************************************\
*** ***
*** ORIGINAL LUA ***
*** ***
*******************************************************************************
** copy of needed original Lua source, which Lua does not export **
\*****************************************************************************/
/*---------------------------------------------------------------------------*\
** Get the C pointer for the value on the stack **
\*---------------------------------------------------------------------------*/
#ifdef LUA_5_1 // > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
/* from Lua 5.1.4 source */
TValue *index2adr (lua_State *L, int idx) {
if (idx > 0) {
TValue *o = L->base + (idx - 1);
api_check(L, idx <= L->ci->top - L->base);
if (o >= L->top) return cast(TValue *, luaO_nilobject);
else return o;
}
else if (idx > LUA_REGISTRYINDEX) {
api_check(L, idx != 0 && -idx <= L->top - L->base);
return L->top + idx;
}
else switch (idx) { /* pseudo-indices */
case LUA_REGISTRYINDEX: return registry(L);
case LUA_ENVIRONINDEX: {
Closure *func = curr_func(L);
sethvalue(L, &L->env, func->c.env);
return &L->env;
}
case LUA_GLOBALSINDEX: return gt(L);
default: {
Closure *func = curr_func(L);
idx = LUA_GLOBALSINDEX - idx;
return (idx <= func->c.nupvalues)
? &func->c.upvalue[idx-1]
: cast(TValue *, luaO_nilobject);
}
}
}
#endif
/*****************************************************************************\
* copy of needed original LuaJIT source, which LuaJIT does not export *
\*****************************************************************************/
/*---------------------------------------------------------------------------*\
** Get the C pointer for the value on the stack **
\*---------------------------------------------------------------------------*/
#ifdef JIT_2 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
/* from jit/src/lj_api.c */
TValue *index2adr(lua_State *L, int idx)
{
if (idx > 0) {
TValue *o = L->base + (idx - 1);
return o < L->top ? o : niltv(L);
} else if (idx > LUA_REGISTRYINDEX) {
api_check(L, idx != 0 && -idx <= L->top - L->base);
return L->top + idx;
} else if (idx == LUA_GLOBALSINDEX) {
TValue *o = &G(L)->tmptv;
settabV(L, o, tabref(L->env));
return o;
} else if (idx == LUA_REGISTRYINDEX) {
return registry(L);
} else {
GCfunc *fn = curr_func(L);
api_check(L, fn->c.gct == ~LJ_TFUNC && !isluafunc(fn));
if (idx == LUA_ENVIRONINDEX) {
TValue *o = &G(L)->tmptv;
settabV(L, o, tabref(fn->c.env));
return o;
} else {
idx = LUA_GLOBALSINDEX - idx;
return idx <= fn->c.nupvalues ? &fn->c.upvalue[idx-1] : niltv(L);
}
}
}
#endif // Lua/JIT < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < <
/* For above original Lua and LuaJIT source, see special notes in LICENSE. */
</code></pre>
<p>And here is a <a href=sample.html>sample</a> on how to use it.</p>
<br />
<center>
<small style='color:gray'>
© 2011 Henning Diedrich
</small>
</center>
</div>
<div class=foot></div>
</body></html>