candle 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. data/LICENSE.txt +20 -0
  2. data/README.md +4 -0
  3. data/VERSION +1 -0
  4. data/bin/candle +21 -0
  5. data/lib/candle.rb +68 -0
  6. data/lib/candle/command.rb +27 -0
  7. data/lib/candle/generators/actions.rb +183 -0
  8. data/lib/candle/generators/blank.rb +127 -0
  9. data/lib/candle/generators/cli.rb +55 -0
  10. data/lib/candle/generators/help.rb +47 -0
  11. data/lib/candle/generators/jam.rb +80 -0
  12. data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
  13. data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
  14. data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
  15. data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
  16. data/lib/candle/generators/lua/wax/bin/hammer +157 -0
  17. data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
  18. data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
  19. data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
  20. data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
  21. data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
  22. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
  23. data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
  24. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
  25. data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
  26. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
  27. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
  28. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
  29. data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
  30. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
  31. data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
  32. data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
  33. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
  34. data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
  35. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
  36. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
  37. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
  38. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
  39. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
  40. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
  41. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
  42. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
  43. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
  44. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
  45. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
  46. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
  47. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
  48. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
  49. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
  50. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
  51. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
  52. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
  53. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
  54. data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
  55. data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
  56. data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
  57. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
  58. data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
  59. data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
  60. data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
  61. data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
  62. data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
  63. data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
  64. data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
  65. data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
  66. data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
  67. data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
  68. data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
  69. data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
  70. data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
  71. data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
  72. data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
  73. data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
  74. data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
  75. data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
  76. data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
  77. data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
  78. data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
  79. data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
  80. data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
  81. data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
  82. data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
  83. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
  84. data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
  85. data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
  86. data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
  87. data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
  88. data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
  89. data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
  90. data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
  91. data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
  92. data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
  93. data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
  94. data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
  95. data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
  96. data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
  97. data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
  98. data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
  99. data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
  100. data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
  101. data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
  102. data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
  103. data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
  104. data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
  105. data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
  106. data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
  107. data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
  108. data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
  109. data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
  110. data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
  111. data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
  112. data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
  113. data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
  114. data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
  115. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
  116. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
  117. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
  118. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
  119. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
  120. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
  121. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
  122. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
  123. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
  124. data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
  125. data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
  126. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
  127. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
  128. data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
  129. data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
  130. data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
  131. data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
  132. data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
  133. data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
  134. data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
  135. data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
  136. data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
  137. data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
  138. data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
  139. data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
  140. data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
  141. data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
  142. data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
  143. data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
  144. data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
  145. data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
  146. data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
  147. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
  148. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  149. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  150. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
  151. data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
  152. data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
  153. data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
  154. data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
  155. data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
  156. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
  157. data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
  158. data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
  159. data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
  160. data/lib/candle/tasks.rb +22 -0
  161. data/lib/candle/utility.rb +30 -0
  162. data/lib/candle/version.rb +9 -0
  163. data/lib/candle/view.rb +48 -0
  164. metadata +582 -0
@@ -0,0 +1,53 @@
1
+ /*
2
+ ** $Id: lualib.h,v 1.36.1.1 2007/12/27 13:02:25 roberto Exp $
3
+ ** Lua standard libraries
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #ifndef lualib_h
9
+ #define lualib_h
10
+
11
+ #include "lua.h"
12
+
13
+
14
+ /* Key to file-handle type */
15
+ #define LUA_FILEHANDLE "FILE*"
16
+
17
+
18
+ #define LUA_COLIBNAME "coroutine"
19
+ LUALIB_API int (luaopen_base) (lua_State *L);
20
+
21
+ #define LUA_TABLIBNAME "table"
22
+ LUALIB_API int (luaopen_table) (lua_State *L);
23
+
24
+ #define LUA_IOLIBNAME "io"
25
+ LUALIB_API int (luaopen_io) (lua_State *L);
26
+
27
+ #define LUA_OSLIBNAME "os"
28
+ LUALIB_API int (luaopen_os) (lua_State *L);
29
+
30
+ #define LUA_STRLIBNAME "string"
31
+ LUALIB_API int (luaopen_string) (lua_State *L);
32
+
33
+ #define LUA_MATHLIBNAME "math"
34
+ LUALIB_API int (luaopen_math) (lua_State *L);
35
+
36
+ #define LUA_DBLIBNAME "debug"
37
+ LUALIB_API int (luaopen_debug) (lua_State *L);
38
+
39
+ #define LUA_LOADLIBNAME "package"
40
+ LUALIB_API int (luaopen_package) (lua_State *L);
41
+
42
+
43
+ /* open all previous libraries */
44
+ LUALIB_API void (luaL_openlibs) (lua_State *L);
45
+
46
+
47
+
48
+ #ifndef lua_assert
49
+ #define lua_assert(x) ((void)0)
50
+ #endif
51
+
52
+
53
+ #endif
@@ -0,0 +1,227 @@
1
+ /*
2
+ ** $Id: lundump.c,v 2.7.1.4 2008/04/04 19:51:41 roberto Exp $
3
+ ** load precompiled Lua chunks
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #include <string.h>
8
+
9
+ #define lundump_c
10
+ #define LUA_CORE
11
+
12
+ #include "lua.h"
13
+
14
+ #include "ldebug.h"
15
+ #include "ldo.h"
16
+ #include "lfunc.h"
17
+ #include "lmem.h"
18
+ #include "lobject.h"
19
+ #include "lstring.h"
20
+ #include "lundump.h"
21
+ #include "lzio.h"
22
+
23
+ typedef struct {
24
+ lua_State* L;
25
+ ZIO* Z;
26
+ Mbuffer* b;
27
+ const char* name;
28
+ } LoadState;
29
+
30
+ #ifdef LUAC_TRUST_BINARIES
31
+ #define IF(c,s)
32
+ #define error(S,s)
33
+ #else
34
+ #define IF(c,s) if (c) error(S,s)
35
+
36
+ static void error(LoadState* S, const char* why)
37
+ {
38
+ luaO_pushfstring(S->L,"%s: %s in precompiled chunk",S->name,why);
39
+ luaD_throw(S->L,LUA_ERRSYNTAX);
40
+ }
41
+ #endif
42
+
43
+ #define LoadMem(S,b,n,size) LoadBlock(S,b,(n)*(size))
44
+ #define LoadByte(S) (lu_byte)LoadChar(S)
45
+ #define LoadVar(S,x) LoadMem(S,&x,1,sizeof(x))
46
+ #define LoadVector(S,b,n,size) LoadMem(S,b,n,size)
47
+
48
+ static void LoadBlock(LoadState* S, void* b, size_t size)
49
+ {
50
+ size_t r=luaZ_read(S->Z,b,size);
51
+ IF (r!=0, "unexpected end");
52
+ }
53
+
54
+ static int LoadChar(LoadState* S)
55
+ {
56
+ char x;
57
+ LoadVar(S,x);
58
+ return x;
59
+ }
60
+
61
+ static int LoadInt(LoadState* S)
62
+ {
63
+ int x;
64
+ LoadVar(S,x);
65
+ IF (x<0, "bad integer");
66
+ return x;
67
+ }
68
+
69
+ static lua_Number LoadNumber(LoadState* S)
70
+ {
71
+ lua_Number x;
72
+ LoadVar(S,x);
73
+ return x;
74
+ }
75
+
76
+ static TString* LoadString(LoadState* S)
77
+ {
78
+ size_t size;
79
+ LoadVar(S,size);
80
+ if (size==0)
81
+ return NULL;
82
+ else
83
+ {
84
+ char* s=luaZ_openspace(S->L,S->b,size);
85
+ LoadBlock(S,s,size);
86
+ return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */
87
+ }
88
+ }
89
+
90
+ static void LoadCode(LoadState* S, Proto* f)
91
+ {
92
+ int n=LoadInt(S);
93
+ f->code=luaM_newvector(S->L,n,Instruction);
94
+ f->sizecode=n;
95
+ LoadVector(S,f->code,n,sizeof(Instruction));
96
+ }
97
+
98
+ static Proto* LoadFunction(LoadState* S, TString* p);
99
+
100
+ static void LoadConstants(LoadState* S, Proto* f)
101
+ {
102
+ int i,n;
103
+ n=LoadInt(S);
104
+ f->k=luaM_newvector(S->L,n,TValue);
105
+ f->sizek=n;
106
+ for (i=0; i<n; i++) setnilvalue(&f->k[i]);
107
+ for (i=0; i<n; i++)
108
+ {
109
+ TValue* o=&f->k[i];
110
+ int t=LoadChar(S);
111
+ switch (t)
112
+ {
113
+ case LUA_TNIL:
114
+ setnilvalue(o);
115
+ break;
116
+ case LUA_TBOOLEAN:
117
+ setbvalue(o,LoadChar(S)!=0);
118
+ break;
119
+ case LUA_TNUMBER:
120
+ setnvalue(o,LoadNumber(S));
121
+ break;
122
+ case LUA_TSTRING:
123
+ setsvalue2n(S->L,o,LoadString(S));
124
+ break;
125
+ default:
126
+ error(S,"bad constant");
127
+ break;
128
+ }
129
+ }
130
+ n=LoadInt(S);
131
+ f->p=luaM_newvector(S->L,n,Proto*);
132
+ f->sizep=n;
133
+ for (i=0; i<n; i++) f->p[i]=NULL;
134
+ for (i=0; i<n; i++) f->p[i]=LoadFunction(S,f->source);
135
+ }
136
+
137
+ static void LoadDebug(LoadState* S, Proto* f)
138
+ {
139
+ int i,n;
140
+ n=LoadInt(S);
141
+ f->lineinfo=luaM_newvector(S->L,n,int);
142
+ f->sizelineinfo=n;
143
+ LoadVector(S,f->lineinfo,n,sizeof(int));
144
+ n=LoadInt(S);
145
+ f->locvars=luaM_newvector(S->L,n,LocVar);
146
+ f->sizelocvars=n;
147
+ for (i=0; i<n; i++) f->locvars[i].varname=NULL;
148
+ for (i=0; i<n; i++)
149
+ {
150
+ f->locvars[i].varname=LoadString(S);
151
+ f->locvars[i].startpc=LoadInt(S);
152
+ f->locvars[i].endpc=LoadInt(S);
153
+ }
154
+ n=LoadInt(S);
155
+ f->upvalues=luaM_newvector(S->L,n,TString*);
156
+ f->sizeupvalues=n;
157
+ for (i=0; i<n; i++) f->upvalues[i]=NULL;
158
+ for (i=0; i<n; i++) f->upvalues[i]=LoadString(S);
159
+ }
160
+
161
+ static Proto* LoadFunction(LoadState* S, TString* p)
162
+ {
163
+ Proto* f;
164
+ if (++S->L->nCcalls > LUAI_MAXCCALLS) error(S,"code too deep");
165
+ f=luaF_newproto(S->L);
166
+ setptvalue2s(S->L,S->L->top,f); incr_top(S->L);
167
+ f->source=LoadString(S); if (f->source==NULL) f->source=p;
168
+ f->linedefined=LoadInt(S);
169
+ f->lastlinedefined=LoadInt(S);
170
+ f->nups=LoadByte(S);
171
+ f->numparams=LoadByte(S);
172
+ f->is_vararg=LoadByte(S);
173
+ f->maxstacksize=LoadByte(S);
174
+ LoadCode(S,f);
175
+ LoadConstants(S,f);
176
+ LoadDebug(S,f);
177
+ IF (!luaG_checkcode(f), "bad code");
178
+ S->L->top--;
179
+ S->L->nCcalls--;
180
+ return f;
181
+ }
182
+
183
+ static void LoadHeader(LoadState* S)
184
+ {
185
+ char h[LUAC_HEADERSIZE];
186
+ char s[LUAC_HEADERSIZE];
187
+ luaU_header(h);
188
+ LoadBlock(S,s,LUAC_HEADERSIZE);
189
+ IF (memcmp(h,s,LUAC_HEADERSIZE)!=0, "bad header");
190
+ }
191
+
192
+ /*
193
+ ** load precompiled chunk
194
+ */
195
+ Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name)
196
+ {
197
+ LoadState S;
198
+ if (*name=='@' || *name=='=')
199
+ S.name=name+1;
200
+ else if (*name==LUA_SIGNATURE[0])
201
+ S.name="binary string";
202
+ else
203
+ S.name=name;
204
+ S.L=L;
205
+ S.Z=Z;
206
+ S.b=buff;
207
+ LoadHeader(&S);
208
+ return LoadFunction(&S,luaS_newliteral(L,"=?"));
209
+ }
210
+
211
+ /*
212
+ * make header
213
+ */
214
+ void luaU_header (char* h)
215
+ {
216
+ int x=1;
217
+ memcpy(h,LUA_SIGNATURE,sizeof(LUA_SIGNATURE)-1);
218
+ h+=sizeof(LUA_SIGNATURE)-1;
219
+ *h++=(char)LUAC_VERSION;
220
+ *h++=(char)LUAC_FORMAT;
221
+ *h++=(char)*(char*)&x; /* endianness */
222
+ *h++=(char)sizeof(int);
223
+ *h++=(char)sizeof(size_t);
224
+ *h++=(char)sizeof(Instruction);
225
+ *h++=(char)sizeof(lua_Number);
226
+ *h++=(char)(((lua_Number)0.5)==0); /* is lua_Number integral? */
227
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ ** $Id: lundump.h,v 1.37.1.1 2007/12/27 13:02:25 roberto Exp $
3
+ ** load precompiled Lua chunks
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+ #ifndef lundump_h
8
+ #define lundump_h
9
+
10
+ #include "lobject.h"
11
+ #include "lzio.h"
12
+
13
+ /* load one chunk; from lundump.c */
14
+ LUAI_FUNC Proto* luaU_undump (lua_State* L, ZIO* Z, Mbuffer* buff, const char* name);
15
+
16
+ /* make header; from lundump.c */
17
+ LUAI_FUNC void luaU_header (char* h);
18
+
19
+ /* dump one chunk; from ldump.c */
20
+ LUAI_FUNC int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip);
21
+
22
+ #ifdef luac_c
23
+ /* print one chunk; from print.c */
24
+ LUAI_FUNC void luaU_print (const Proto* f, int full);
25
+ #endif
26
+
27
+ /* for header of binary files -- this is Lua 5.1 */
28
+ #define LUAC_VERSION 0x51
29
+
30
+ /* for header of binary files -- this is the official format */
31
+ #define LUAC_FORMAT 0
32
+
33
+ /* size of header of binary files */
34
+ #define LUAC_HEADERSIZE 12
35
+
36
+ #endif
@@ -0,0 +1,763 @@
1
+ /*
2
+ ** $Id: lvm.c,v 2.63.1.3 2007/12/28 15:32:23 roberto Exp $
3
+ ** Lua virtual machine
4
+ ** See Copyright Notice in lua.h
5
+ */
6
+
7
+
8
+ #include <stdio.h>
9
+ #include <stdlib.h>
10
+ #include <string.h>
11
+
12
+ #define lvm_c
13
+ #define LUA_CORE
14
+
15
+ #include "lua.h"
16
+
17
+ #include "ldebug.h"
18
+ #include "ldo.h"
19
+ #include "lfunc.h"
20
+ #include "lgc.h"
21
+ #include "lobject.h"
22
+ #include "lopcodes.h"
23
+ #include "lstate.h"
24
+ #include "lstring.h"
25
+ #include "ltable.h"
26
+ #include "ltm.h"
27
+ #include "lvm.h"
28
+
29
+
30
+
31
+ /* limit for table tag-method chains (to avoid loops) */
32
+ #define MAXTAGLOOP 100
33
+
34
+
35
+ const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
36
+ lua_Number num;
37
+ if (ttisnumber(obj)) return obj;
38
+ if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) {
39
+ setnvalue(n, num);
40
+ return n;
41
+ }
42
+ else
43
+ return NULL;
44
+ }
45
+
46
+
47
+ int luaV_tostring (lua_State *L, StkId obj) {
48
+ if (!ttisnumber(obj))
49
+ return 0;
50
+ else {
51
+ char s[LUAI_MAXNUMBER2STR];
52
+ lua_Number n = nvalue(obj);
53
+ lua_number2str(s, n);
54
+ setsvalue2s(L, obj, luaS_new(L, s));
55
+ return 1;
56
+ }
57
+ }
58
+
59
+
60
+ static void traceexec (lua_State *L, const Instruction *pc) {
61
+ lu_byte mask = L->hookmask;
62
+ const Instruction *oldpc = L->savedpc;
63
+ L->savedpc = pc;
64
+ if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) {
65
+ resethookcount(L);
66
+ luaD_callhook(L, LUA_HOOKCOUNT, -1);
67
+ }
68
+ if (mask & LUA_MASKLINE) {
69
+ Proto *p = ci_func(L->ci)->l.p;
70
+ int npc = pcRel(pc, p);
71
+ int newline = getline(p, npc);
72
+ /* call linehook when enter a new function, when jump back (loop),
73
+ or when enter a new line */
74
+ if (npc == 0 || pc <= oldpc || newline != getline(p, pcRel(oldpc, p)))
75
+ luaD_callhook(L, LUA_HOOKLINE, newline);
76
+ }
77
+ }
78
+
79
+
80
+ static void callTMres (lua_State *L, StkId res, const TValue *f,
81
+ const TValue *p1, const TValue *p2) {
82
+ ptrdiff_t result = savestack(L, res);
83
+ setobj2s(L, L->top, f); /* push function */
84
+ setobj2s(L, L->top+1, p1); /* 1st argument */
85
+ setobj2s(L, L->top+2, p2); /* 2nd argument */
86
+ luaD_checkstack(L, 3);
87
+ L->top += 3;
88
+ luaD_call(L, L->top - 3, 1);
89
+ res = restorestack(L, result);
90
+ L->top--;
91
+ setobjs2s(L, res, L->top);
92
+ }
93
+
94
+
95
+
96
+ static void callTM (lua_State *L, const TValue *f, const TValue *p1,
97
+ const TValue *p2, const TValue *p3) {
98
+ setobj2s(L, L->top, f); /* push function */
99
+ setobj2s(L, L->top+1, p1); /* 1st argument */
100
+ setobj2s(L, L->top+2, p2); /* 2nd argument */
101
+ setobj2s(L, L->top+3, p3); /* 3th argument */
102
+ luaD_checkstack(L, 4);
103
+ L->top += 4;
104
+ luaD_call(L, L->top - 4, 0);
105
+ }
106
+
107
+
108
+ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
109
+ int loop;
110
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
111
+ const TValue *tm;
112
+ if (ttistable(t)) { /* `t' is a table? */
113
+ Table *h = hvalue(t);
114
+ const TValue *res = luaH_get(h, key); /* do a primitive get */
115
+ if (!ttisnil(res) || /* result is no nil? */
116
+ (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
117
+ setobj2s(L, val, res);
118
+ return;
119
+ }
120
+ /* else will try the tag method */
121
+ }
122
+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
123
+ luaG_typeerror(L, t, "index");
124
+ if (ttisfunction(tm)) {
125
+ callTMres(L, val, tm, t, key);
126
+ return;
127
+ }
128
+ t = tm; /* else repeat with `tm' */
129
+ }
130
+ luaG_runerror(L, "loop in gettable");
131
+ }
132
+
133
+
134
+ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
135
+ int loop;
136
+ for (loop = 0; loop < MAXTAGLOOP; loop++) {
137
+ const TValue *tm;
138
+ if (ttistable(t)) { /* `t' is a table? */
139
+ Table *h = hvalue(t);
140
+ TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
141
+ if (!ttisnil(oldval) || /* result is no nil? */
142
+ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) { /* or no TM? */
143
+ setobj2t(L, oldval, val);
144
+ luaC_barriert(L, h, val);
145
+ return;
146
+ }
147
+ /* else will try the tag method */
148
+ }
149
+ else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
150
+ luaG_typeerror(L, t, "index");
151
+ if (ttisfunction(tm)) {
152
+ callTM(L, tm, t, key, val);
153
+ return;
154
+ }
155
+ t = tm; /* else repeat with `tm' */
156
+ }
157
+ luaG_runerror(L, "loop in settable");
158
+ }
159
+
160
+
161
+ static int call_binTM (lua_State *L, const TValue *p1, const TValue *p2,
162
+ StkId res, TMS event) {
163
+ const TValue *tm = luaT_gettmbyobj(L, p1, event); /* try first operand */
164
+ if (ttisnil(tm))
165
+ tm = luaT_gettmbyobj(L, p2, event); /* try second operand */
166
+ if (ttisnil(tm)) return 0;
167
+ callTMres(L, res, tm, p1, p2);
168
+ return 1;
169
+ }
170
+
171
+
172
+ static const TValue *get_compTM (lua_State *L, Table *mt1, Table *mt2,
173
+ TMS event) {
174
+ const TValue *tm1 = fasttm(L, mt1, event);
175
+ const TValue *tm2;
176
+ if (tm1 == NULL) return NULL; /* no metamethod */
177
+ if (mt1 == mt2) return tm1; /* same metatables => same metamethods */
178
+ tm2 = fasttm(L, mt2, event);
179
+ if (tm2 == NULL) return NULL; /* no metamethod */
180
+ if (luaO_rawequalObj(tm1, tm2)) /* same metamethods? */
181
+ return tm1;
182
+ return NULL;
183
+ }
184
+
185
+
186
+ static int call_orderTM (lua_State *L, const TValue *p1, const TValue *p2,
187
+ TMS event) {
188
+ const TValue *tm1 = luaT_gettmbyobj(L, p1, event);
189
+ const TValue *tm2;
190
+ if (ttisnil(tm1)) return -1; /* no metamethod? */
191
+ tm2 = luaT_gettmbyobj(L, p2, event);
192
+ if (!luaO_rawequalObj(tm1, tm2)) /* different metamethods? */
193
+ return -1;
194
+ callTMres(L, L->top, tm1, p1, p2);
195
+ return !l_isfalse(L->top);
196
+ }
197
+
198
+
199
+ static int l_strcmp (const TString *ls, const TString *rs) {
200
+ const char *l = getstr(ls);
201
+ size_t ll = ls->tsv.len;
202
+ const char *r = getstr(rs);
203
+ size_t lr = rs->tsv.len;
204
+ for (;;) {
205
+ int temp = strcoll(l, r);
206
+ if (temp != 0) return temp;
207
+ else { /* strings are equal up to a `\0' */
208
+ size_t len = strlen(l); /* index of first `\0' in both strings */
209
+ if (len == lr) /* r is finished? */
210
+ return (len == ll) ? 0 : 1;
211
+ else if (len == ll) /* l is finished? */
212
+ return -1; /* l is smaller than r (because r is not finished) */
213
+ /* both strings longer than `len'; go on comparing (after the `\0') */
214
+ len++;
215
+ l += len; ll -= len; r += len; lr -= len;
216
+ }
217
+ }
218
+ }
219
+
220
+
221
+ int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r) {
222
+ int res;
223
+ if (ttype(l) != ttype(r))
224
+ return luaG_ordererror(L, l, r);
225
+ else if (ttisnumber(l))
226
+ return luai_numlt(nvalue(l), nvalue(r));
227
+ else if (ttisstring(l))
228
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
229
+ else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
230
+ return res;
231
+ return luaG_ordererror(L, l, r);
232
+ }
233
+
234
+
235
+ static int lessequal (lua_State *L, const TValue *l, const TValue *r) {
236
+ int res;
237
+ if (ttype(l) != ttype(r))
238
+ return luaG_ordererror(L, l, r);
239
+ else if (ttisnumber(l))
240
+ return luai_numle(nvalue(l), nvalue(r));
241
+ else if (ttisstring(l))
242
+ return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
243
+ else if ((res = call_orderTM(L, l, r, TM_LE)) != -1) /* first try `le' */
244
+ return res;
245
+ else if ((res = call_orderTM(L, r, l, TM_LT)) != -1) /* else try `lt' */
246
+ return !res;
247
+ return luaG_ordererror(L, l, r);
248
+ }
249
+
250
+
251
+ int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2) {
252
+ const TValue *tm;
253
+ lua_assert(ttype(t1) == ttype(t2));
254
+ switch (ttype(t1)) {
255
+ case LUA_TNIL: return 1;
256
+ case LUA_TNUMBER: return luai_numeq(nvalue(t1), nvalue(t2));
257
+ case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
258
+ case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
259
+ case LUA_TUSERDATA: {
260
+ if (uvalue(t1) == uvalue(t2)) return 1;
261
+ tm = get_compTM(L, uvalue(t1)->metatable, uvalue(t2)->metatable,
262
+ TM_EQ);
263
+ break; /* will try TM */
264
+ }
265
+ case LUA_TTABLE: {
266
+ if (hvalue(t1) == hvalue(t2)) return 1;
267
+ tm = get_compTM(L, hvalue(t1)->metatable, hvalue(t2)->metatable, TM_EQ);
268
+ break; /* will try TM */
269
+ }
270
+ default: return gcvalue(t1) == gcvalue(t2);
271
+ }
272
+ if (tm == NULL) return 0; /* no TM? */
273
+ callTMres(L, L->top, tm, t1, t2); /* call TM */
274
+ return !l_isfalse(L->top);
275
+ }
276
+
277
+
278
+ void luaV_concat (lua_State *L, int total, int last) {
279
+ do {
280
+ StkId top = L->base + last + 1;
281
+ int n = 2; /* number of elements handled in this pass (at least 2) */
282
+ if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
283
+ if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
284
+ luaG_concaterror(L, top-2, top-1);
285
+ } else if (tsvalue(top-1)->len == 0) /* second op is empty? */
286
+ (void)tostring(L, top - 2); /* result is first op (as string) */
287
+ else {
288
+ /* at least two string values; get as many as possible */
289
+ size_t tl = tsvalue(top-1)->len;
290
+ char *buffer;
291
+ int i;
292
+ /* collect total length */
293
+ for (n = 1; n < total && tostring(L, top-n-1); n++) {
294
+ size_t l = tsvalue(top-n-1)->len;
295
+ if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow");
296
+ tl += l;
297
+ }
298
+ buffer = luaZ_openspace(L, &G(L)->buff, tl);
299
+ tl = 0;
300
+ for (i=n; i>0; i--) { /* concat all strings */
301
+ size_t l = tsvalue(top-i)->len;
302
+ memcpy(buffer+tl, svalue(top-i), l);
303
+ tl += l;
304
+ }
305
+ setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
306
+ }
307
+ total -= n-1; /* got `n' strings to create 1 new */
308
+ last -= n-1;
309
+ } while (total > 1); /* repeat until only 1 result left */
310
+ }
311
+
312
+
313
+ static void Arith (lua_State *L, StkId ra, const TValue *rb,
314
+ const TValue *rc, TMS op) {
315
+ TValue tempb, tempc;
316
+ const TValue *b, *c;
317
+ if ((b = luaV_tonumber(rb, &tempb)) != NULL &&
318
+ (c = luaV_tonumber(rc, &tempc)) != NULL) {
319
+ lua_Number nb = nvalue(b), nc = nvalue(c);
320
+ switch (op) {
321
+ case TM_ADD: setnvalue(ra, luai_numadd(nb, nc)); break;
322
+ case TM_SUB: setnvalue(ra, luai_numsub(nb, nc)); break;
323
+ case TM_MUL: setnvalue(ra, luai_nummul(nb, nc)); break;
324
+ case TM_DIV: setnvalue(ra, luai_numdiv(nb, nc)); break;
325
+ case TM_MOD: setnvalue(ra, luai_nummod(nb, nc)); break;
326
+ case TM_POW: setnvalue(ra, luai_numpow(nb, nc)); break;
327
+ case TM_UNM: setnvalue(ra, luai_numunm(nb)); break;
328
+ default: lua_assert(0); break;
329
+ }
330
+ }
331
+ else if (!call_binTM(L, rb, rc, ra, op))
332
+ luaG_aritherror(L, rb, rc);
333
+ }
334
+
335
+
336
+
337
+ /*
338
+ ** some macros for common tasks in `luaV_execute'
339
+ */
340
+
341
+ #define runtime_check(L, c) { if (!(c)) break; }
342
+
343
+ #define RA(i) (base+GETARG_A(i))
344
+ /* to be used after possible stack reallocation */
345
+ #define RB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgR, base+GETARG_B(i))
346
+ #define RC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgR, base+GETARG_C(i))
347
+ #define RKB(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, \
348
+ ISK(GETARG_B(i)) ? k+INDEXK(GETARG_B(i)) : base+GETARG_B(i))
349
+ #define RKC(i) check_exp(getCMode(GET_OPCODE(i)) == OpArgK, \
350
+ ISK(GETARG_C(i)) ? k+INDEXK(GETARG_C(i)) : base+GETARG_C(i))
351
+ #define KBx(i) check_exp(getBMode(GET_OPCODE(i)) == OpArgK, k+GETARG_Bx(i))
352
+
353
+
354
+ #define dojump(L,pc,i) {(pc) += (i); luai_threadyield(L);}
355
+
356
+
357
+ #define Protect(x) { L->savedpc = pc; {x;}; base = L->base; }
358
+
359
+
360
+ #define arith_op(op,tm) { \
361
+ TValue *rb = RKB(i); \
362
+ TValue *rc = RKC(i); \
363
+ if (ttisnumber(rb) && ttisnumber(rc)) { \
364
+ lua_Number nb = nvalue(rb), nc = nvalue(rc); \
365
+ setnvalue(ra, op(nb, nc)); \
366
+ } \
367
+ else \
368
+ Protect(Arith(L, ra, rb, rc, tm)); \
369
+ }
370
+
371
+
372
+
373
+ void luaV_execute (lua_State *L, int nexeccalls) {
374
+ LClosure *cl;
375
+ StkId base;
376
+ TValue *k;
377
+ const Instruction *pc;
378
+ reentry: /* entry point */
379
+ lua_assert(isLua(L->ci));
380
+ pc = L->savedpc;
381
+ cl = &clvalue(L->ci->func)->l;
382
+ base = L->base;
383
+ k = cl->p->k;
384
+ /* main loop of interpreter */
385
+ for (;;) {
386
+ const Instruction i = *pc++;
387
+ StkId ra;
388
+ if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
389
+ (--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
390
+ traceexec(L, pc);
391
+ if (L->status == LUA_YIELD) { /* did hook yield? */
392
+ L->savedpc = pc - 1;
393
+ return;
394
+ }
395
+ base = L->base;
396
+ }
397
+ /* warning!! several calls may realloc the stack and invalidate `ra' */
398
+ ra = RA(i);
399
+ lua_assert(base == L->base && L->base == L->ci->base);
400
+ lua_assert(base <= L->top && L->top <= L->stack + L->stacksize);
401
+ lua_assert(L->top == L->ci->top || luaG_checkopenop(i));
402
+ switch (GET_OPCODE(i)) {
403
+ case OP_MOVE: {
404
+ setobjs2s(L, ra, RB(i));
405
+ continue;
406
+ }
407
+ case OP_LOADK: {
408
+ setobj2s(L, ra, KBx(i));
409
+ continue;
410
+ }
411
+ case OP_LOADBOOL: {
412
+ setbvalue(ra, GETARG_B(i));
413
+ if (GETARG_C(i)) pc++; /* skip next instruction (if C) */
414
+ continue;
415
+ }
416
+ case OP_LOADNIL: {
417
+ TValue *rb = RB(i);
418
+ do {
419
+ setnilvalue(rb--);
420
+ } while (rb >= ra);
421
+ continue;
422
+ }
423
+ case OP_GETUPVAL: {
424
+ int b = GETARG_B(i);
425
+ setobj2s(L, ra, cl->upvals[b]->v);
426
+ continue;
427
+ }
428
+ case OP_GETGLOBAL: {
429
+ TValue g;
430
+ TValue *rb = KBx(i);
431
+ sethvalue(L, &g, cl->env);
432
+ lua_assert(ttisstring(rb));
433
+ Protect(luaV_gettable(L, &g, rb, ra));
434
+ continue;
435
+ }
436
+ case OP_GETTABLE: {
437
+ Protect(luaV_gettable(L, RB(i), RKC(i), ra));
438
+ continue;
439
+ }
440
+ case OP_SETGLOBAL: {
441
+ TValue g;
442
+ sethvalue(L, &g, cl->env);
443
+ lua_assert(ttisstring(KBx(i)));
444
+ Protect(luaV_settable(L, &g, KBx(i), ra));
445
+ continue;
446
+ }
447
+ case OP_SETUPVAL: {
448
+ UpVal *uv = cl->upvals[GETARG_B(i)];
449
+ setobj(L, uv->v, ra);
450
+ luaC_barrier(L, uv, ra);
451
+ continue;
452
+ }
453
+ case OP_SETTABLE: {
454
+ Protect(luaV_settable(L, ra, RKB(i), RKC(i)));
455
+ continue;
456
+ }
457
+ case OP_NEWTABLE: {
458
+ int b = GETARG_B(i);
459
+ int c = GETARG_C(i);
460
+ sethvalue(L, ra, luaH_new(L, luaO_fb2int(b), luaO_fb2int(c)));
461
+ Protect(luaC_checkGC(L));
462
+ continue;
463
+ }
464
+ case OP_SELF: {
465
+ StkId rb = RB(i);
466
+ setobjs2s(L, ra+1, rb);
467
+ Protect(luaV_gettable(L, rb, RKC(i), ra));
468
+ continue;
469
+ }
470
+ case OP_ADD: {
471
+ arith_op(luai_numadd, TM_ADD);
472
+ continue;
473
+ }
474
+ case OP_SUB: {
475
+ arith_op(luai_numsub, TM_SUB);
476
+ continue;
477
+ }
478
+ case OP_MUL: {
479
+ arith_op(luai_nummul, TM_MUL);
480
+ continue;
481
+ }
482
+ case OP_DIV: {
483
+ arith_op(luai_numdiv, TM_DIV);
484
+ continue;
485
+ }
486
+ case OP_MOD: {
487
+ arith_op(luai_nummod, TM_MOD);
488
+ continue;
489
+ }
490
+ case OP_POW: {
491
+ arith_op(luai_numpow, TM_POW);
492
+ continue;
493
+ }
494
+ case OP_UNM: {
495
+ TValue *rb = RB(i);
496
+ if (ttisnumber(rb)) {
497
+ lua_Number nb = nvalue(rb);
498
+ setnvalue(ra, luai_numunm(nb));
499
+ }
500
+ else {
501
+ Protect(Arith(L, ra, rb, rb, TM_UNM));
502
+ }
503
+ continue;
504
+ }
505
+ case OP_NOT: {
506
+ int res = l_isfalse(RB(i)); /* next assignment may change this value */
507
+ setbvalue(ra, res);
508
+ continue;
509
+ }
510
+ case OP_LEN: {
511
+ const TValue *rb = RB(i);
512
+ switch (ttype(rb)) {
513
+ case LUA_TTABLE: {
514
+ setnvalue(ra, cast_num(luaH_getn(hvalue(rb))));
515
+ break;
516
+ }
517
+ case LUA_TSTRING: {
518
+ setnvalue(ra, cast_num(tsvalue(rb)->len));
519
+ break;
520
+ }
521
+ default: { /* try metamethod */
522
+ Protect(
523
+ if (!call_binTM(L, rb, luaO_nilobject, ra, TM_LEN))
524
+ luaG_typeerror(L, rb, "get length of");
525
+ )
526
+ }
527
+ }
528
+ continue;
529
+ }
530
+ case OP_CONCAT: {
531
+ int b = GETARG_B(i);
532
+ int c = GETARG_C(i);
533
+ Protect(luaV_concat(L, c-b+1, c); luaC_checkGC(L));
534
+ setobjs2s(L, RA(i), base+b);
535
+ continue;
536
+ }
537
+ case OP_JMP: {
538
+ dojump(L, pc, GETARG_sBx(i));
539
+ continue;
540
+ }
541
+ case OP_EQ: {
542
+ TValue *rb = RKB(i);
543
+ TValue *rc = RKC(i);
544
+ Protect(
545
+ if (equalobj(L, rb, rc) == GETARG_A(i))
546
+ dojump(L, pc, GETARG_sBx(*pc));
547
+ )
548
+ pc++;
549
+ continue;
550
+ }
551
+ case OP_LT: {
552
+ Protect(
553
+ if (luaV_lessthan(L, RKB(i), RKC(i)) == GETARG_A(i))
554
+ dojump(L, pc, GETARG_sBx(*pc));
555
+ )
556
+ pc++;
557
+ continue;
558
+ }
559
+ case OP_LE: {
560
+ Protect(
561
+ if (lessequal(L, RKB(i), RKC(i)) == GETARG_A(i))
562
+ dojump(L, pc, GETARG_sBx(*pc));
563
+ )
564
+ pc++;
565
+ continue;
566
+ }
567
+ case OP_TEST: {
568
+ if (l_isfalse(ra) != GETARG_C(i))
569
+ dojump(L, pc, GETARG_sBx(*pc));
570
+ pc++;
571
+ continue;
572
+ }
573
+ case OP_TESTSET: {
574
+ TValue *rb = RB(i);
575
+ if (l_isfalse(rb) != GETARG_C(i)) {
576
+ setobjs2s(L, ra, rb);
577
+ dojump(L, pc, GETARG_sBx(*pc));
578
+ }
579
+ pc++;
580
+ continue;
581
+ }
582
+ case OP_CALL: {
583
+ int b = GETARG_B(i);
584
+ int nresults = GETARG_C(i) - 1;
585
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
586
+ L->savedpc = pc;
587
+ switch (luaD_precall(L, ra, nresults)) {
588
+ case PCRLUA: {
589
+ nexeccalls++;
590
+ goto reentry; /* restart luaV_execute over new Lua function */
591
+ }
592
+ case PCRC: {
593
+ /* it was a C function (`precall' called it); adjust results */
594
+ if (nresults >= 0) L->top = L->ci->top;
595
+ base = L->base;
596
+ continue;
597
+ }
598
+ default: {
599
+ return; /* yield */
600
+ }
601
+ }
602
+ }
603
+ case OP_TAILCALL: {
604
+ int b = GETARG_B(i);
605
+ if (b != 0) L->top = ra+b; /* else previous instruction set top */
606
+ L->savedpc = pc;
607
+ lua_assert(GETARG_C(i) - 1 == LUA_MULTRET);
608
+ switch (luaD_precall(L, ra, LUA_MULTRET)) {
609
+ case PCRLUA: {
610
+ /* tail call: put new frame in place of previous one */
611
+ CallInfo *ci = L->ci - 1; /* previous frame */
612
+ int aux;
613
+ StkId func = ci->func;
614
+ StkId pfunc = (ci+1)->func; /* previous function index */
615
+ if (L->openupval) luaF_close(L, ci->base);
616
+ L->base = ci->base = ci->func + ((ci+1)->base - pfunc);
617
+ for (aux = 0; pfunc+aux < L->top; aux++) /* move frame down */
618
+ setobjs2s(L, func+aux, pfunc+aux);
619
+ ci->top = L->top = func+aux; /* correct top */
620
+ lua_assert(L->top == L->base + clvalue(func)->l.p->maxstacksize);
621
+ ci->savedpc = L->savedpc;
622
+ ci->tailcalls++; /* one more call lost */
623
+ L->ci--; /* remove new frame */
624
+ goto reentry;
625
+ }
626
+ case PCRC: { /* it was a C function (`precall' called it) */
627
+ base = L->base;
628
+ continue;
629
+ }
630
+ default: {
631
+ return; /* yield */
632
+ }
633
+ }
634
+ }
635
+ case OP_RETURN: {
636
+ int b = GETARG_B(i);
637
+ if (b != 0) L->top = ra+b-1;
638
+ if (L->openupval) luaF_close(L, base);
639
+ L->savedpc = pc;
640
+ b = luaD_poscall(L, ra);
641
+ if (--nexeccalls == 0) /* was previous function running `here'? */
642
+ return; /* no: return */
643
+ else { /* yes: continue its execution */
644
+ if (b) L->top = L->ci->top;
645
+ lua_assert(isLua(L->ci));
646
+ lua_assert(GET_OPCODE(*((L->ci)->savedpc - 1)) == OP_CALL);
647
+ goto reentry;
648
+ }
649
+ }
650
+ case OP_FORLOOP: {
651
+ lua_Number step = nvalue(ra+2);
652
+ lua_Number idx = luai_numadd(nvalue(ra), step); /* increment index */
653
+ lua_Number limit = nvalue(ra+1);
654
+ if (luai_numlt(0, step) ? luai_numle(idx, limit)
655
+ : luai_numle(limit, idx)) {
656
+ dojump(L, pc, GETARG_sBx(i)); /* jump back */
657
+ setnvalue(ra, idx); /* update internal index... */
658
+ setnvalue(ra+3, idx); /* ...and external index */
659
+ }
660
+ continue;
661
+ }
662
+ case OP_FORPREP: {
663
+ const TValue *init = ra;
664
+ const TValue *plimit = ra+1;
665
+ const TValue *pstep = ra+2;
666
+ L->savedpc = pc; /* next steps may throw errors */
667
+ if (!tonumber(init, ra))
668
+ luaG_runerror(L, LUA_QL("for") " initial value must be a number");
669
+ else if (!tonumber(plimit, ra+1))
670
+ luaG_runerror(L, LUA_QL("for") " limit must be a number");
671
+ else if (!tonumber(pstep, ra+2))
672
+ luaG_runerror(L, LUA_QL("for") " step must be a number");
673
+ setnvalue(ra, luai_numsub(nvalue(ra), nvalue(pstep)));
674
+ dojump(L, pc, GETARG_sBx(i));
675
+ continue;
676
+ }
677
+ case OP_TFORLOOP: {
678
+ StkId cb = ra + 3; /* call base */
679
+ setobjs2s(L, cb+2, ra+2);
680
+ setobjs2s(L, cb+1, ra+1);
681
+ setobjs2s(L, cb, ra);
682
+ L->top = cb+3; /* func. + 2 args (state and index) */
683
+ Protect(luaD_call(L, cb, GETARG_C(i)));
684
+ L->top = L->ci->top;
685
+ cb = RA(i) + 3; /* previous call may change the stack */
686
+ if (!ttisnil(cb)) { /* continue loop? */
687
+ setobjs2s(L, cb-1, cb); /* save control variable */
688
+ dojump(L, pc, GETARG_sBx(*pc)); /* jump back */
689
+ }
690
+ pc++;
691
+ continue;
692
+ }
693
+ case OP_SETLIST: {
694
+ int n = GETARG_B(i);
695
+ int c = GETARG_C(i);
696
+ int last;
697
+ Table *h;
698
+ if (n == 0) {
699
+ n = cast_int(L->top - ra) - 1;
700
+ L->top = L->ci->top;
701
+ }
702
+ if (c == 0) c = cast_int(*pc++);
703
+ runtime_check(L, ttistable(ra));
704
+ h = hvalue(ra);
705
+ last = ((c-1)*LFIELDS_PER_FLUSH) + n;
706
+ if (last > h->sizearray) /* needs more space? */
707
+ luaH_resizearray(L, h, last); /* pre-alloc it at once */
708
+ for (; n > 0; n--) {
709
+ TValue *val = ra+n;
710
+ setobj2t(L, luaH_setnum(L, h, last--), val);
711
+ luaC_barriert(L, h, val);
712
+ }
713
+ continue;
714
+ }
715
+ case OP_CLOSE: {
716
+ luaF_close(L, ra);
717
+ continue;
718
+ }
719
+ case OP_CLOSURE: {
720
+ Proto *p;
721
+ Closure *ncl;
722
+ int nup, j;
723
+ p = cl->p->p[GETARG_Bx(i)];
724
+ nup = p->nups;
725
+ ncl = luaF_newLclosure(L, nup, cl->env);
726
+ ncl->l.p = p;
727
+ for (j=0; j<nup; j++, pc++) {
728
+ if (GET_OPCODE(*pc) == OP_GETUPVAL)
729
+ ncl->l.upvals[j] = cl->upvals[GETARG_B(*pc)];
730
+ else {
731
+ lua_assert(GET_OPCODE(*pc) == OP_MOVE);
732
+ ncl->l.upvals[j] = luaF_findupval(L, base + GETARG_B(*pc));
733
+ }
734
+ }
735
+ setclvalue(L, ra, ncl);
736
+ Protect(luaC_checkGC(L));
737
+ continue;
738
+ }
739
+ case OP_VARARG: {
740
+ int b = GETARG_B(i) - 1;
741
+ int j;
742
+ CallInfo *ci = L->ci;
743
+ int n = cast_int(ci->base - ci->func) - cl->p->numparams - 1;
744
+ if (b == LUA_MULTRET) {
745
+ Protect(luaD_checkstack(L, n));
746
+ ra = RA(i); /* previous call may change the stack */
747
+ b = n;
748
+ L->top = ra + n;
749
+ }
750
+ for (j = 0; j < b; j++) {
751
+ if (j < n) {
752
+ setobjs2s(L, ra + j, ci->base - n + j);
753
+ }
754
+ else {
755
+ setnilvalue(ra + j);
756
+ }
757
+ }
758
+ continue;
759
+ }
760
+ }
761
+ }
762
+ }
763
+