candle 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/VERSION +1 -0
- data/bin/candle +21 -0
- data/lib/candle.rb +68 -0
- data/lib/candle/command.rb +27 -0
- data/lib/candle/generators/actions.rb +183 -0
- data/lib/candle/generators/blank.rb +127 -0
- data/lib/candle/generators/cli.rb +55 -0
- data/lib/candle/generators/help.rb +47 -0
- data/lib/candle/generators/jam.rb +80 -0
- data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
- data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
- data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
- data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
- data/lib/candle/generators/lua/wax/bin/hammer +157 -0
- data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
- data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
- data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
- data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
- data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
- data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
- data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
- data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
- data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
- data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
- data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
- data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
- data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
- data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
- data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
- data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
- data/lib/candle/tasks.rb +22 -0
- data/lib/candle/utility.rb +30 -0
- data/lib/candle/version.rb +9 -0
- data/lib/candle/view.rb +48 -0
- metadata +582 -0
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lparser.h,v 1.57.1.1 2007/12/27 13:02:25 roberto Exp $
|
3
|
+
** Lua Parser
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lparser_h
|
8
|
+
#define lparser_h
|
9
|
+
|
10
|
+
#include "llimits.h"
|
11
|
+
#include "lobject.h"
|
12
|
+
#include "lzio.h"
|
13
|
+
|
14
|
+
|
15
|
+
/*
|
16
|
+
** Expression descriptor
|
17
|
+
*/
|
18
|
+
|
19
|
+
typedef enum {
|
20
|
+
VVOID, /* no value */
|
21
|
+
VNIL,
|
22
|
+
VTRUE,
|
23
|
+
VFALSE,
|
24
|
+
VK, /* info = index of constant in `k' */
|
25
|
+
VKNUM, /* nval = numerical value */
|
26
|
+
VLOCAL, /* info = local register */
|
27
|
+
VUPVAL, /* info = index of upvalue in `upvalues' */
|
28
|
+
VGLOBAL, /* info = index of table; aux = index of global name in `k' */
|
29
|
+
VINDEXED, /* info = table register; aux = index register (or `k') */
|
30
|
+
VJMP, /* info = instruction pc */
|
31
|
+
VRELOCABLE, /* info = instruction pc */
|
32
|
+
VNONRELOC, /* info = result register */
|
33
|
+
VCALL, /* info = instruction pc */
|
34
|
+
VVARARG /* info = instruction pc */
|
35
|
+
} expkind;
|
36
|
+
|
37
|
+
typedef struct expdesc {
|
38
|
+
expkind k;
|
39
|
+
union {
|
40
|
+
struct { int info, aux; } s;
|
41
|
+
lua_Number nval;
|
42
|
+
} u;
|
43
|
+
int t; /* patch list of `exit when true' */
|
44
|
+
int f; /* patch list of `exit when false' */
|
45
|
+
} expdesc;
|
46
|
+
|
47
|
+
|
48
|
+
typedef struct upvaldesc {
|
49
|
+
lu_byte k;
|
50
|
+
lu_byte info;
|
51
|
+
} upvaldesc;
|
52
|
+
|
53
|
+
|
54
|
+
struct BlockCnt; /* defined in lparser.c */
|
55
|
+
|
56
|
+
|
57
|
+
/* state needed to generate code for a given function */
|
58
|
+
typedef struct FuncState {
|
59
|
+
Proto *f; /* current function header */
|
60
|
+
Table *h; /* table to find (and reuse) elements in `k' */
|
61
|
+
struct FuncState *prev; /* enclosing function */
|
62
|
+
struct LexState *ls; /* lexical state */
|
63
|
+
struct lua_State *L; /* copy of the Lua state */
|
64
|
+
struct BlockCnt *bl; /* chain of current blocks */
|
65
|
+
int pc; /* next position to code (equivalent to `ncode') */
|
66
|
+
int lasttarget; /* `pc' of last `jump target' */
|
67
|
+
int jpc; /* list of pending jumps to `pc' */
|
68
|
+
int freereg; /* first free register */
|
69
|
+
int nk; /* number of elements in `k' */
|
70
|
+
int np; /* number of elements in `p' */
|
71
|
+
short nlocvars; /* number of elements in `locvars' */
|
72
|
+
lu_byte nactvar; /* number of active local variables */
|
73
|
+
upvaldesc upvalues[LUAI_MAXUPVALUES]; /* upvalues */
|
74
|
+
unsigned short actvar[LUAI_MAXVARS]; /* declared-variable stack */
|
75
|
+
} FuncState;
|
76
|
+
|
77
|
+
|
78
|
+
LUAI_FUNC Proto *luaY_parser (lua_State *L, ZIO *z, Mbuffer *buff,
|
79
|
+
const char *name);
|
80
|
+
|
81
|
+
|
82
|
+
#endif
|
@@ -0,0 +1,214 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lstate.c,v 2.36.1.2 2008/01/03 15:20:39 roberto Exp $
|
3
|
+
** Global State
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#include <stddef.h>
|
9
|
+
|
10
|
+
#define lstate_c
|
11
|
+
#define LUA_CORE
|
12
|
+
|
13
|
+
#include "lua.h"
|
14
|
+
|
15
|
+
#include "ldebug.h"
|
16
|
+
#include "ldo.h"
|
17
|
+
#include "lfunc.h"
|
18
|
+
#include "lgc.h"
|
19
|
+
#include "llex.h"
|
20
|
+
#include "lmem.h"
|
21
|
+
#include "lstate.h"
|
22
|
+
#include "lstring.h"
|
23
|
+
#include "ltable.h"
|
24
|
+
#include "ltm.h"
|
25
|
+
|
26
|
+
|
27
|
+
#define state_size(x) (sizeof(x) + LUAI_EXTRASPACE)
|
28
|
+
#define fromstate(l) (cast(lu_byte *, (l)) - LUAI_EXTRASPACE)
|
29
|
+
#define tostate(l) (cast(lua_State *, cast(lu_byte *, l) + LUAI_EXTRASPACE))
|
30
|
+
|
31
|
+
|
32
|
+
/*
|
33
|
+
** Main thread combines a thread state and the global state
|
34
|
+
*/
|
35
|
+
typedef struct LG {
|
36
|
+
lua_State l;
|
37
|
+
global_State g;
|
38
|
+
} LG;
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
static void stack_init (lua_State *L1, lua_State *L) {
|
43
|
+
/* initialize CallInfo array */
|
44
|
+
L1->base_ci = luaM_newvector(L, BASIC_CI_SIZE, CallInfo);
|
45
|
+
L1->ci = L1->base_ci;
|
46
|
+
L1->size_ci = BASIC_CI_SIZE;
|
47
|
+
L1->end_ci = L1->base_ci + L1->size_ci - 1;
|
48
|
+
/* initialize stack array */
|
49
|
+
L1->stack = luaM_newvector(L, BASIC_STACK_SIZE + EXTRA_STACK, TValue);
|
50
|
+
L1->stacksize = BASIC_STACK_SIZE + EXTRA_STACK;
|
51
|
+
L1->top = L1->stack;
|
52
|
+
L1->stack_last = L1->stack+(L1->stacksize - EXTRA_STACK)-1;
|
53
|
+
/* initialize first ci */
|
54
|
+
L1->ci->func = L1->top;
|
55
|
+
setnilvalue(L1->top++); /* `function' entry for this `ci' */
|
56
|
+
L1->base = L1->ci->base = L1->top;
|
57
|
+
L1->ci->top = L1->top + LUA_MINSTACK;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
static void freestack (lua_State *L, lua_State *L1) {
|
62
|
+
luaM_freearray(L, L1->base_ci, L1->size_ci, CallInfo);
|
63
|
+
luaM_freearray(L, L1->stack, L1->stacksize, TValue);
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
/*
|
68
|
+
** open parts that may cause memory-allocation errors
|
69
|
+
*/
|
70
|
+
static void f_luaopen (lua_State *L, void *ud) {
|
71
|
+
global_State *g = G(L);
|
72
|
+
UNUSED(ud);
|
73
|
+
stack_init(L, L); /* init stack */
|
74
|
+
sethvalue(L, gt(L), luaH_new(L, 0, 2)); /* table of globals */
|
75
|
+
sethvalue(L, registry(L), luaH_new(L, 0, 2)); /* registry */
|
76
|
+
luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
|
77
|
+
luaT_init(L);
|
78
|
+
luaX_init(L);
|
79
|
+
luaS_fix(luaS_newliteral(L, MEMERRMSG));
|
80
|
+
g->GCthreshold = 4*g->totalbytes;
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
static void preinit_state (lua_State *L, global_State *g) {
|
85
|
+
G(L) = g;
|
86
|
+
L->stack = NULL;
|
87
|
+
L->stacksize = 0;
|
88
|
+
L->errorJmp = NULL;
|
89
|
+
L->hook = NULL;
|
90
|
+
L->hookmask = 0;
|
91
|
+
L->basehookcount = 0;
|
92
|
+
L->allowhook = 1;
|
93
|
+
resethookcount(L);
|
94
|
+
L->openupval = NULL;
|
95
|
+
L->size_ci = 0;
|
96
|
+
L->nCcalls = L->baseCcalls = 0;
|
97
|
+
L->status = 0;
|
98
|
+
L->base_ci = L->ci = NULL;
|
99
|
+
L->savedpc = NULL;
|
100
|
+
L->errfunc = 0;
|
101
|
+
setnilvalue(gt(L));
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
static void close_state (lua_State *L) {
|
106
|
+
global_State *g = G(L);
|
107
|
+
luaF_close(L, L->stack); /* close all upvalues for this thread */
|
108
|
+
luaC_freeall(L); /* collect all objects */
|
109
|
+
lua_assert(g->rootgc == obj2gco(L));
|
110
|
+
lua_assert(g->strt.nuse == 0);
|
111
|
+
luaM_freearray(L, G(L)->strt.hash, G(L)->strt.size, TString *);
|
112
|
+
luaZ_freebuffer(L, &g->buff);
|
113
|
+
freestack(L, L);
|
114
|
+
lua_assert(g->totalbytes == sizeof(LG));
|
115
|
+
(*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
|
116
|
+
}
|
117
|
+
|
118
|
+
|
119
|
+
lua_State *luaE_newthread (lua_State *L) {
|
120
|
+
lua_State *L1 = tostate(luaM_malloc(L, state_size(lua_State)));
|
121
|
+
luaC_link(L, obj2gco(L1), LUA_TTHREAD);
|
122
|
+
preinit_state(L1, G(L));
|
123
|
+
stack_init(L1, L); /* init stack */
|
124
|
+
setobj2n(L, gt(L1), gt(L)); /* share table of globals */
|
125
|
+
L1->hookmask = L->hookmask;
|
126
|
+
L1->basehookcount = L->basehookcount;
|
127
|
+
L1->hook = L->hook;
|
128
|
+
resethookcount(L1);
|
129
|
+
lua_assert(iswhite(obj2gco(L1)));
|
130
|
+
return L1;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
void luaE_freethread (lua_State *L, lua_State *L1) {
|
135
|
+
luaF_close(L1, L1->stack); /* close all upvalues for this thread */
|
136
|
+
lua_assert(L1->openupval == NULL);
|
137
|
+
luai_userstatefree(L1);
|
138
|
+
freestack(L, L1);
|
139
|
+
luaM_freemem(L, fromstate(L1), state_size(lua_State));
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
144
|
+
int i;
|
145
|
+
lua_State *L;
|
146
|
+
global_State *g;
|
147
|
+
void *l = (*f)(ud, NULL, 0, state_size(LG));
|
148
|
+
if (l == NULL) return NULL;
|
149
|
+
L = tostate(l);
|
150
|
+
g = &((LG *)L)->g;
|
151
|
+
L->next = NULL;
|
152
|
+
L->tt = LUA_TTHREAD;
|
153
|
+
g->currentwhite = bit2mask(WHITE0BIT, FIXEDBIT);
|
154
|
+
L->marked = luaC_white(g);
|
155
|
+
set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
|
156
|
+
preinit_state(L, g);
|
157
|
+
g->frealloc = f;
|
158
|
+
g->ud = ud;
|
159
|
+
g->mainthread = L;
|
160
|
+
g->uvhead.u.l.prev = &g->uvhead;
|
161
|
+
g->uvhead.u.l.next = &g->uvhead;
|
162
|
+
g->GCthreshold = 0; /* mark it as unfinished state */
|
163
|
+
g->strt.size = 0;
|
164
|
+
g->strt.nuse = 0;
|
165
|
+
g->strt.hash = NULL;
|
166
|
+
setnilvalue(registry(L));
|
167
|
+
luaZ_initbuffer(L, &g->buff);
|
168
|
+
g->panic = NULL;
|
169
|
+
g->gcstate = GCSpause;
|
170
|
+
g->rootgc = obj2gco(L);
|
171
|
+
g->sweepstrgc = 0;
|
172
|
+
g->sweepgc = &g->rootgc;
|
173
|
+
g->gray = NULL;
|
174
|
+
g->grayagain = NULL;
|
175
|
+
g->weak = NULL;
|
176
|
+
g->tmudata = NULL;
|
177
|
+
g->totalbytes = sizeof(LG);
|
178
|
+
g->gcpause = LUAI_GCPAUSE;
|
179
|
+
g->gcstepmul = LUAI_GCMUL;
|
180
|
+
g->gcdept = 0;
|
181
|
+
for (i=0; i<NUM_TAGS; i++) g->mt[i] = NULL;
|
182
|
+
if (luaD_rawrunprotected(L, f_luaopen, NULL) != 0) {
|
183
|
+
/* memory allocation error: free partial state */
|
184
|
+
close_state(L);
|
185
|
+
L = NULL;
|
186
|
+
}
|
187
|
+
else
|
188
|
+
luai_userstateopen(L);
|
189
|
+
return L;
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
static void callallgcTM (lua_State *L, void *ud) {
|
194
|
+
UNUSED(ud);
|
195
|
+
luaC_callGCTM(L); /* call GC metamethods for all udata */
|
196
|
+
}
|
197
|
+
|
198
|
+
|
199
|
+
LUA_API void lua_close (lua_State *L) {
|
200
|
+
L = G(L)->mainthread; /* only the main thread can be closed */
|
201
|
+
lua_lock(L);
|
202
|
+
luaF_close(L, L->stack); /* close all upvalues for this thread */
|
203
|
+
luaC_separateudata(L, 1); /* separate udata that have GC metamethods */
|
204
|
+
L->errfunc = 0; /* no error function during GC metamethods */
|
205
|
+
do { /* repeat until no more errors */
|
206
|
+
L->ci = L->base_ci;
|
207
|
+
L->base = L->top = L->ci->base;
|
208
|
+
L->nCcalls = L->baseCcalls = 0;
|
209
|
+
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0);
|
210
|
+
lua_assert(G(L)->tmudata == NULL);
|
211
|
+
luai_userstateclose(L);
|
212
|
+
close_state(L);
|
213
|
+
}
|
214
|
+
|
@@ -0,0 +1,169 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $
|
3
|
+
** Global State
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lstate_h
|
8
|
+
#define lstate_h
|
9
|
+
|
10
|
+
#include "lua.h"
|
11
|
+
|
12
|
+
#include "lobject.h"
|
13
|
+
#include "ltm.h"
|
14
|
+
#include "lzio.h"
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
struct lua_longjmp; /* defined in ldo.c */
|
19
|
+
|
20
|
+
|
21
|
+
/* table of globals */
|
22
|
+
#define gt(L) (&L->l_gt)
|
23
|
+
|
24
|
+
/* registry */
|
25
|
+
#define registry(L) (&G(L)->l_registry)
|
26
|
+
|
27
|
+
|
28
|
+
/* extra stack space to handle TM calls and some other extras */
|
29
|
+
#define EXTRA_STACK 5
|
30
|
+
|
31
|
+
|
32
|
+
#define BASIC_CI_SIZE 8
|
33
|
+
|
34
|
+
#define BASIC_STACK_SIZE (2*LUA_MINSTACK)
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
typedef struct stringtable {
|
39
|
+
GCObject **hash;
|
40
|
+
lu_int32 nuse; /* number of elements */
|
41
|
+
int size;
|
42
|
+
} stringtable;
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
** informations about a call
|
47
|
+
*/
|
48
|
+
typedef struct CallInfo {
|
49
|
+
StkId base; /* base for this function */
|
50
|
+
StkId func; /* function index in the stack */
|
51
|
+
StkId top; /* top for this function */
|
52
|
+
const Instruction *savedpc;
|
53
|
+
int nresults; /* expected number of results from this function */
|
54
|
+
int tailcalls; /* number of tail calls lost under this entry */
|
55
|
+
} CallInfo;
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
#define curr_func(L) (clvalue(L->ci->func))
|
60
|
+
#define ci_func(ci) (clvalue((ci)->func))
|
61
|
+
#define f_isLua(ci) (!ci_func(ci)->c.isC)
|
62
|
+
#define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
|
63
|
+
|
64
|
+
|
65
|
+
/*
|
66
|
+
** `global state', shared by all threads of this state
|
67
|
+
*/
|
68
|
+
typedef struct global_State {
|
69
|
+
stringtable strt; /* hash table for strings */
|
70
|
+
lua_Alloc frealloc; /* function to reallocate memory */
|
71
|
+
void *ud; /* auxiliary data to `frealloc' */
|
72
|
+
lu_byte currentwhite;
|
73
|
+
lu_byte gcstate; /* state of garbage collector */
|
74
|
+
int sweepstrgc; /* position of sweep in `strt' */
|
75
|
+
GCObject *rootgc; /* list of all collectable objects */
|
76
|
+
GCObject **sweepgc; /* position of sweep in `rootgc' */
|
77
|
+
GCObject *gray; /* list of gray objects */
|
78
|
+
GCObject *grayagain; /* list of objects to be traversed atomically */
|
79
|
+
GCObject *weak; /* list of weak tables (to be cleared) */
|
80
|
+
GCObject *tmudata; /* last element of list of userdata to be GC */
|
81
|
+
Mbuffer buff; /* temporary buffer for string concatentation */
|
82
|
+
lu_mem GCthreshold;
|
83
|
+
lu_mem totalbytes; /* number of bytes currently allocated */
|
84
|
+
lu_mem estimate; /* an estimate of number of bytes actually in use */
|
85
|
+
lu_mem gcdept; /* how much GC is `behind schedule' */
|
86
|
+
int gcpause; /* size of pause between successive GCs */
|
87
|
+
int gcstepmul; /* GC `granularity' */
|
88
|
+
lua_CFunction panic; /* to be called in unprotected errors */
|
89
|
+
TValue l_registry;
|
90
|
+
struct lua_State *mainthread;
|
91
|
+
UpVal uvhead; /* head of double-linked list of all open upvalues */
|
92
|
+
struct Table *mt[NUM_TAGS]; /* metatables for basic types */
|
93
|
+
TString *tmname[TM_N]; /* array with tag-method names */
|
94
|
+
} global_State;
|
95
|
+
|
96
|
+
|
97
|
+
/*
|
98
|
+
** `per thread' state
|
99
|
+
*/
|
100
|
+
struct lua_State {
|
101
|
+
CommonHeader;
|
102
|
+
lu_byte status;
|
103
|
+
StkId top; /* first free slot in the stack */
|
104
|
+
StkId base; /* base of current function */
|
105
|
+
global_State *l_G;
|
106
|
+
CallInfo *ci; /* call info for current function */
|
107
|
+
const Instruction *savedpc; /* `savedpc' of current function */
|
108
|
+
StkId stack_last; /* last free slot in the stack */
|
109
|
+
StkId stack; /* stack base */
|
110
|
+
CallInfo *end_ci; /* points after end of ci array*/
|
111
|
+
CallInfo *base_ci; /* array of CallInfo's */
|
112
|
+
int stacksize;
|
113
|
+
int size_ci; /* size of array `base_ci' */
|
114
|
+
unsigned short nCcalls; /* number of nested C calls */
|
115
|
+
unsigned short baseCcalls; /* nested C calls when resuming coroutine */
|
116
|
+
lu_byte hookmask;
|
117
|
+
lu_byte allowhook;
|
118
|
+
int basehookcount;
|
119
|
+
int hookcount;
|
120
|
+
lua_Hook hook;
|
121
|
+
TValue l_gt; /* table of globals */
|
122
|
+
TValue env; /* temporary place for environments */
|
123
|
+
GCObject *openupval; /* list of open upvalues in this stack */
|
124
|
+
GCObject *gclist;
|
125
|
+
struct lua_longjmp *errorJmp; /* current error recover point */
|
126
|
+
ptrdiff_t errfunc; /* current error handling function (stack index) */
|
127
|
+
};
|
128
|
+
|
129
|
+
|
130
|
+
#define G(L) (L->l_G)
|
131
|
+
|
132
|
+
|
133
|
+
/*
|
134
|
+
** Union of all collectable objects
|
135
|
+
*/
|
136
|
+
union GCObject {
|
137
|
+
GCheader gch;
|
138
|
+
union TString ts;
|
139
|
+
union Udata u;
|
140
|
+
union Closure cl;
|
141
|
+
struct Table h;
|
142
|
+
struct Proto p;
|
143
|
+
struct UpVal uv;
|
144
|
+
struct lua_State th; /* thread */
|
145
|
+
};
|
146
|
+
|
147
|
+
|
148
|
+
/* macros to convert a GCObject into a specific value */
|
149
|
+
#define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
|
150
|
+
#define gco2ts(o) (&rawgco2ts(o)->tsv)
|
151
|
+
#define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
|
152
|
+
#define gco2u(o) (&rawgco2u(o)->uv)
|
153
|
+
#define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
|
154
|
+
#define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
|
155
|
+
#define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
|
156
|
+
#define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
157
|
+
#define ngcotouv(o) \
|
158
|
+
check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
|
159
|
+
#define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
|
160
|
+
|
161
|
+
/* macro to convert any Lua object into a GCObject */
|
162
|
+
#define obj2gco(v) (cast(GCObject *, (v)))
|
163
|
+
|
164
|
+
|
165
|
+
LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
|
166
|
+
LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
|
167
|
+
|
168
|
+
#endif
|
169
|
+
|