dub 0.2.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dub might be problematic. Click here for more details.
- data/History.txt +92 -0
- data/LICENSE +20 -0
- data/README.rdoc +115 -0
- data/Rakefile +59 -0
- data/dub.gemspec +197 -0
- data/lib/dub/argument.rb +286 -0
- data/lib/dub/entities_unescape.rb +9 -0
- data/lib/dub/function.rb +177 -0
- data/lib/dub/function_group.rb +72 -0
- data/lib/dub/generator.rb +15 -0
- data/lib/dub/group.rb +20 -0
- data/lib/dub/klass.rb +338 -0
- data/lib/dub/lua/class.cpp.erb +114 -0
- data/lib/dub/lua/class_gen.rb +96 -0
- data/lib/dub/lua/function.cpp.erb +15 -0
- data/lib/dub/lua/function_gen.rb +329 -0
- data/lib/dub/lua/group.cpp.erb +9 -0
- data/lib/dub/lua/lua_cpp_helper.cpp +259 -0
- data/lib/dub/lua/lua_cpp_helper.h +219 -0
- data/lib/dub/lua/lua_object.cpp +158 -0
- data/lib/dub/lua/lua_object.h +69 -0
- data/lib/dub/lua/namespace.cpp.erb +42 -0
- data/lib/dub/lua/namespace_gen.rb +69 -0
- data/lib/dub/lua.rb +24 -0
- data/lib/dub/member_extraction.rb +128 -0
- data/lib/dub/namespace.rb +295 -0
- data/lib/dub/opts_parser.rb +30 -0
- data/lib/dub/parser.rb +46 -0
- data/lib/dub/templates/lua_template.erb +21 -0
- data/lib/dub/version.rb +3 -0
- data/lib/dub.rb +24 -20
- data/test/argument_test.rb +581 -0
- data/test/fixtures/app/CMakeLists.txt +54 -0
- data/test/fixtures/app/Doxyfile +1600 -0
- data/test/fixtures/app/bindings/all_lua.cpp +299 -0
- data/test/fixtures/app/include/matrix.h +283 -0
- data/test/fixtures/app/make_lua_bindings.rb +13 -0
- data/test/fixtures/app/vendor/lua/CMakeLists.txt +25 -0
- data/test/fixtures/app/vendor/lua/COPYRIGHT +34 -0
- data/test/fixtures/app/vendor/lua/HISTORY +183 -0
- data/test/fixtures/app/vendor/lua/INSTALL +99 -0
- data/test/fixtures/app/vendor/lua/Makefile +183 -0
- data/test/fixtures/app/vendor/lua/README +37 -0
- data/test/fixtures/app/vendor/lua/lapi.c +1080 -0
- data/test/fixtures/app/vendor/lua/lapi.h +16 -0
- data/test/fixtures/app/vendor/lua/lauxlib.c +653 -0
- data/test/fixtures/app/vendor/lua/lauxlib.h +174 -0
- data/test/fixtures/app/vendor/lua/lbaselib.c +643 -0
- data/test/fixtures/app/vendor/lua/lcode.c +839 -0
- data/test/fixtures/app/vendor/lua/lcode.h +76 -0
- data/test/fixtures/app/vendor/lua/ldblib.c +397 -0
- data/test/fixtures/app/vendor/lua/ldebug.c +622 -0
- data/test/fixtures/app/vendor/lua/ldebug.h +33 -0
- data/test/fixtures/app/vendor/lua/ldo.c +516 -0
- data/test/fixtures/app/vendor/lua/ldo.h +57 -0
- data/test/fixtures/app/vendor/lua/ldump.c +164 -0
- data/test/fixtures/app/vendor/lua/lfunc.c +174 -0
- data/test/fixtures/app/vendor/lua/lfunc.h +34 -0
- data/test/fixtures/app/vendor/lua/lgc.c +711 -0
- data/test/fixtures/app/vendor/lua/lgc.h +110 -0
- data/test/fixtures/app/vendor/lua/liblua.a +0 -0
- data/test/fixtures/app/vendor/lua/linit.c +38 -0
- data/test/fixtures/app/vendor/lua/liolib.c +532 -0
- data/test/fixtures/app/vendor/lua/llex.c +461 -0
- data/test/fixtures/app/vendor/lua/llex.h +81 -0
- data/test/fixtures/app/vendor/lua/llimits.h +128 -0
- data/test/fixtures/app/vendor/lua/lmathlib.c +263 -0
- data/test/fixtures/app/vendor/lua/lmem.c +86 -0
- data/test/fixtures/app/vendor/lua/lmem.h +49 -0
- data/test/fixtures/app/vendor/lua/loadlib.c +664 -0
- data/test/fixtures/app/vendor/lua/lobject.c +214 -0
- data/test/fixtures/app/vendor/lua/lobject.h +381 -0
- data/test/fixtures/app/vendor/lua/lopcodes.c +102 -0
- data/test/fixtures/app/vendor/lua/lopcodes.h +268 -0
- data/test/fixtures/app/vendor/lua/loslib.c +244 -0
- data/test/fixtures/app/vendor/lua/lparser.c +1337 -0
- data/test/fixtures/app/vendor/lua/lparser.h +82 -0
- data/test/fixtures/app/vendor/lua/lstate.c +214 -0
- data/test/fixtures/app/vendor/lua/lstate.h +168 -0
- data/test/fixtures/app/vendor/lua/lstring.c +111 -0
- data/test/fixtures/app/vendor/lua/lstring.h +31 -0
- data/test/fixtures/app/vendor/lua/lstrlib.c +868 -0
- data/test/fixtures/app/vendor/lua/ltable.c +588 -0
- data/test/fixtures/app/vendor/lua/ltable.h +40 -0
- data/test/fixtures/app/vendor/lua/ltablib.c +278 -0
- data/test/fixtures/app/vendor/lua/ltm.c +75 -0
- data/test/fixtures/app/vendor/lua/ltm.h +54 -0
- data/test/fixtures/app/vendor/lua/lua.c +695 -0
- data/test/fixtures/app/vendor/lua/lua.h +385 -0
- data/test/fixtures/app/vendor/lua/lua_dub_helper.h +77 -0
- data/test/fixtures/app/vendor/lua/luac +0 -0
- data/test/fixtures/app/vendor/lua/luac.c +200 -0
- data/test/fixtures/app/vendor/lua/luaconf.h +762 -0
- data/test/fixtures/app/vendor/lua/lualib.h +53 -0
- data/test/fixtures/app/vendor/lua/lundump.c +223 -0
- data/test/fixtures/app/vendor/lua/lundump.h +36 -0
- data/test/fixtures/app/vendor/lua/lvm.c +765 -0
- data/test/fixtures/app/vendor/lua/lvm.h +36 -0
- data/test/fixtures/app/vendor/lua/lzio.c +82 -0
- data/test/fixtures/app/vendor/lua/lzio.h +67 -0
- data/test/fixtures/app/vendor/lua/matrix.h +102 -0
- data/test/fixtures/app/vendor/lua/print.c +227 -0
- data/test/fixtures/app/vendor/lua/test/README +26 -0
- data/test/fixtures/app/vendor/lua/test/bisect.lua +27 -0
- data/test/fixtures/app/vendor/lua/test/cf.lua +16 -0
- data/test/fixtures/app/vendor/lua/test/echo.lua +5 -0
- data/test/fixtures/app/vendor/lua/test/env.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/factorial.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/fib.lua +40 -0
- data/test/fixtures/app/vendor/lua/test/fibfor.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/globals.lua +13 -0
- data/test/fixtures/app/vendor/lua/test/hello.lua +3 -0
- data/test/fixtures/app/vendor/lua/test/life.lua +111 -0
- data/test/fixtures/app/vendor/lua/test/luac.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/printf.lua +7 -0
- data/test/fixtures/app/vendor/lua/test/readonly.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/sieve.lua +29 -0
- data/test/fixtures/app/vendor/lua/test/sort.lua +66 -0
- data/test/fixtures/app/vendor/lua/test/table.lua +12 -0
- data/test/fixtures/app/vendor/lua/test/trace-calls.lua +32 -0
- data/test/fixtures/app/vendor/lua/test/trace-globals.lua +38 -0
- data/test/fixtures/app/vendor/lua/test/xd.lua +14 -0
- data/test/fixtures/app/xml/classdub_1_1_base.xml +85 -0
- data/test/fixtures/app/xml/classdub_1_1_custom_destructor.xml +67 -0
- data/test/fixtures/app/xml/classdub_1_1_deletable_out_of_lua.xml +43 -0
- data/test/fixtures/app/xml/classdub_1_1_matrix.xml +482 -0
- data/test/fixtures/app/xml/classdub_1_1_no_destructor.xml +49 -0
- data/test/fixtures/app/xml/classdub_1_1_priv_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_private_constr.xml +68 -0
- data/test/fixtures/app/xml/classdub_1_1_static_constr.xml +69 -0
- data/test/fixtures/app/xml/classdub_1_1_sub_base.xml +89 -0
- data/test/fixtures/app/xml/classdub_1_1_t_mat.xml +252 -0
- data/test/fixtures/app/xml/combine.xslt +15 -0
- data/test/fixtures/app/xml/compound.xsd +814 -0
- data/test/fixtures/app/xml/dir_53661a2bdeb1d55e60581a7e15deb763.xml +12 -0
- data/test/fixtures/app/xml/index.xml +91 -0
- data/test/fixtures/app/xml/index.xsd +66 -0
- data/test/fixtures/app/xml/matrix_8h.xml +310 -0
- data/test/fixtures/app/xml/namespacedub.xml +48 -0
- data/test/fixtures/classcv_1_1_mat.xml +1996 -0
- data/test/fixtures/classcv_1_1_point__.xml +341 -0
- data/test/fixtures/classcv_1_1_scalar__.xml +269 -0
- data/test/fixtures/classcv_1_1_size__.xml +270 -0
- data/test/fixtures/dummy_class.cpp.erb +1 -0
- data/test/fixtures/dummy_function.cpp.erb +1 -0
- data/test/fixtures/group___magic_type.xml +406 -0
- data/test/fixtures/namespacecv.xml +12659 -0
- data/test/function_group_test.rb +43 -0
- data/test/function_test.rb +405 -0
- data/test/group_test.rb +241 -0
- data/test/helper.rb +34 -0
- data/test/klass_test.rb +551 -0
- data/test/lua_function_gen_test.rb +242 -0
- data/test/namespace_test.rb +220 -0
- data/test/parser_test.rb +36 -0
- metadata +229 -272
- checksums.yaml +0 -7
- data/lib/open_api_sdk/analytics.rb +0 -99
- data/lib/open_api_sdk/domains.rb +0 -353
- data/lib/open_api_sdk/dub.rb +0 -88
- data/lib/open_api_sdk/links.rb +0 -766
- data/lib/open_api_sdk/metatags.rb +0 -54
- data/lib/open_api_sdk/models/operations/bulkcreatelinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/bulkupdatelinks_requestbody.rb +0 -27
- data/lib/open_api_sdk/models/operations/bulkupdatelinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/color.rb +0 -24
- data/lib/open_api_sdk/models/operations/createdomain_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/createdomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/createlink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/createlink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/createtag_requestbody.rb +0 -32
- data/lib/open_api_sdk/models/operations/createtag_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/data.rb +0 -83
- data/lib/open_api_sdk/models/operations/deletedomain_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletedomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/deletedomain_responsebody.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletelink_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/deletelink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/deletelink_responsebody.rb +0 -24
- data/lib/open_api_sdk/models/operations/event.rb +0 -21
- data/lib/open_api_sdk/models/operations/getlinkinfo_request.rb +0 -33
- data/lib/open_api_sdk/models/operations/getlinkinfo_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getlinks_request.rb +0 -51
- data/lib/open_api_sdk/models/operations/getlinks_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getlinkscount_request.rb +0 -48
- data/lib/open_api_sdk/models/operations/getlinkscount_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getmetatags_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/getmetatags_response.rb +0 -33
- data/lib/open_api_sdk/models/operations/getmetatags_responsebody.rb +0 -30
- data/lib/open_api_sdk/models/operations/getqrcode_request.rb +0 -39
- data/lib/open_api_sdk/models/operations/getqrcode_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/gettags_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/getworkspace_request.rb +0 -24
- data/lib/open_api_sdk/models/operations/getworkspace_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/groupby.rb +0 -28
- data/lib/open_api_sdk/models/operations/interval.rb +0 -25
- data/lib/open_api_sdk/models/operations/level.rb +0 -21
- data/lib/open_api_sdk/models/operations/listdomains_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/paymentprocessor.rb +0 -20
- data/lib/open_api_sdk/models/operations/requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/retrieveanalytics_request.rb +0 -81
- data/lib/open_api_sdk/models/operations/retrieveanalytics_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/sort.rb +0 -20
- data/lib/open_api_sdk/models/operations/trackcustomer_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/trackcustomer_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/trackcustomer_responsebody.rb +0 -33
- data/lib/open_api_sdk/models/operations/tracklead_requestbody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracklead_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/tracklead_responsebody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracksale_requestbody.rb +0 -42
- data/lib/open_api_sdk/models/operations/tracksale_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/tracksale_responsebody.rb +0 -42
- data/lib/open_api_sdk/models/operations/updatedomain_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatedomain_requestbody.rb +0 -33
- data/lib/open_api_sdk/models/operations/updatedomain_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updatelink_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatelink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/updatelink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updatetag_color.rb +0 -24
- data/lib/open_api_sdk/models/operations/updatetag_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updatetag_requestbody.rb +0 -32
- data/lib/open_api_sdk/models/operations/updatetag_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/updateworkspace_request.rb +0 -27
- data/lib/open_api_sdk/models/operations/updateworkspace_requestbody.rb +0 -27
- data/lib/open_api_sdk/models/operations/updateworkspace_response.rb +0 -60
- data/lib/open_api_sdk/models/operations/upsertlink_requestbody.rb +0 -95
- data/lib/open_api_sdk/models/operations/upsertlink_response.rb +0 -60
- data/lib/open_api_sdk/models/operations.rb +0 -74
- data/lib/open_api_sdk/models/shared/badrequest.rb +0 -24
- data/lib/open_api_sdk/models/shared/code.rb +0 -18
- data/lib/open_api_sdk/models/shared/color.rb +0 -24
- data/lib/open_api_sdk/models/shared/conflict.rb +0 -24
- data/lib/open_api_sdk/models/shared/conflict_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/conflict_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/countrycode.rb +0 -267
- data/lib/open_api_sdk/models/shared/domains.rb +0 -27
- data/lib/open_api_sdk/models/shared/domainschema.rb +0 -48
- data/lib/open_api_sdk/models/shared/error.rb +0 -30
- data/lib/open_api_sdk/models/shared/forbidden.rb +0 -24
- data/lib/open_api_sdk/models/shared/forbidden_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/forbidden_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/geo.rb +0 -771
- data/lib/open_api_sdk/models/shared/internalservererror.rb +0 -24
- data/lib/open_api_sdk/models/shared/internalservererror_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/internalservererror_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/inviteexpired.rb +0 -24
- data/lib/open_api_sdk/models/shared/inviteexpired_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/inviteexpired_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/linkgeotargeting.rb +0 -771
- data/lib/open_api_sdk/models/shared/linkschema.rb +0 -142
- data/lib/open_api_sdk/models/shared/notfound.rb +0 -24
- data/lib/open_api_sdk/models/shared/notfound_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/notfound_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/plan.rb +0 -24
- data/lib/open_api_sdk/models/shared/ratelimitexceeded.rb +0 -24
- data/lib/open_api_sdk/models/shared/ratelimitexceeded_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/ratelimitexceeded_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/role.rb +0 -19
- data/lib/open_api_sdk/models/shared/security.rb +0 -24
- data/lib/open_api_sdk/models/shared/tagschema.rb +0 -30
- data/lib/open_api_sdk/models/shared/unauthorized.rb +0 -24
- data/lib/open_api_sdk/models/shared/unauthorized_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/unauthorized_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/unprocessableentity.rb +0 -24
- data/lib/open_api_sdk/models/shared/unprocessableentity_code.rb +0 -18
- data/lib/open_api_sdk/models/shared/unprocessableentity_error.rb +0 -30
- data/lib/open_api_sdk/models/shared/users.rb +0 -24
- data/lib/open_api_sdk/models/shared/workspaceschema.rb +0 -81
- data/lib/open_api_sdk/models/shared.rb +0 -49
- data/lib/open_api_sdk/qr_codes.rb +0 -97
- data/lib/open_api_sdk/sdkconfiguration.rb +0 -52
- data/lib/open_api_sdk/tags.rb +0 -272
- data/lib/open_api_sdk/track.rb +0 -276
- data/lib/open_api_sdk/utils/metadata_fields.rb +0 -150
- data/lib/open_api_sdk/utils/t.rb +0 -59
- data/lib/open_api_sdk/utils/utils.rb +0 -772
- data/lib/open_api_sdk/workspaces.rb +0 -192
@@ -0,0 +1,164 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: ldump.c,v 1.15 2006/02/16 15:53:49 lhf Exp $
|
3
|
+
** save precompiled Lua chunks
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <stddef.h>
|
8
|
+
|
9
|
+
#define ldump_c
|
10
|
+
#define LUA_CORE
|
11
|
+
|
12
|
+
#include "lua.h"
|
13
|
+
|
14
|
+
#include "lobject.h"
|
15
|
+
#include "lstate.h"
|
16
|
+
#include "lundump.h"
|
17
|
+
|
18
|
+
typedef struct {
|
19
|
+
lua_State* L;
|
20
|
+
lua_Writer writer;
|
21
|
+
void* data;
|
22
|
+
int strip;
|
23
|
+
int status;
|
24
|
+
} DumpState;
|
25
|
+
|
26
|
+
#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D)
|
27
|
+
#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D)
|
28
|
+
|
29
|
+
static void DumpBlock(const void* b, size_t size, DumpState* D)
|
30
|
+
{
|
31
|
+
if (D->status==0)
|
32
|
+
{
|
33
|
+
lua_unlock(D->L);
|
34
|
+
D->status=(*D->writer)(D->L,b,size,D->data);
|
35
|
+
lua_lock(D->L);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
static void DumpChar(int y, DumpState* D)
|
40
|
+
{
|
41
|
+
char x=(char)y;
|
42
|
+
DumpVar(x,D);
|
43
|
+
}
|
44
|
+
|
45
|
+
static void DumpInt(int x, DumpState* D)
|
46
|
+
{
|
47
|
+
DumpVar(x,D);
|
48
|
+
}
|
49
|
+
|
50
|
+
static void DumpNumber(lua_Number x, DumpState* D)
|
51
|
+
{
|
52
|
+
DumpVar(x,D);
|
53
|
+
}
|
54
|
+
|
55
|
+
static void DumpVector(const void* b, int n, size_t size, DumpState* D)
|
56
|
+
{
|
57
|
+
DumpInt(n,D);
|
58
|
+
DumpMem(b,n,size,D);
|
59
|
+
}
|
60
|
+
|
61
|
+
static void DumpString(const TString* s, DumpState* D)
|
62
|
+
{
|
63
|
+
if (s==NULL || getstr(s)==NULL)
|
64
|
+
{
|
65
|
+
size_t size=0;
|
66
|
+
DumpVar(size,D);
|
67
|
+
}
|
68
|
+
else
|
69
|
+
{
|
70
|
+
size_t size=s->tsv.len+1; /* include trailing '\0' */
|
71
|
+
DumpVar(size,D);
|
72
|
+
DumpBlock(getstr(s),size,D);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D)
|
77
|
+
|
78
|
+
static void DumpFunction(const Proto* f, const TString* p, DumpState* D);
|
79
|
+
|
80
|
+
static void DumpConstants(const Proto* f, DumpState* D)
|
81
|
+
{
|
82
|
+
int i,n=f->sizek;
|
83
|
+
DumpInt(n,D);
|
84
|
+
for (i=0; i<n; i++)
|
85
|
+
{
|
86
|
+
const TValue* o=&f->k[i];
|
87
|
+
DumpChar(ttype(o),D);
|
88
|
+
switch (ttype(o))
|
89
|
+
{
|
90
|
+
case LUA_TNIL:
|
91
|
+
break;
|
92
|
+
case LUA_TBOOLEAN:
|
93
|
+
DumpChar(bvalue(o),D);
|
94
|
+
break;
|
95
|
+
case LUA_TNUMBER:
|
96
|
+
DumpNumber(nvalue(o),D);
|
97
|
+
break;
|
98
|
+
case LUA_TSTRING:
|
99
|
+
DumpString(rawtsvalue(o),D);
|
100
|
+
break;
|
101
|
+
default:
|
102
|
+
lua_assert(0); /* cannot happen */
|
103
|
+
break;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
n=f->sizep;
|
107
|
+
DumpInt(n,D);
|
108
|
+
for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
|
109
|
+
}
|
110
|
+
|
111
|
+
static void DumpDebug(const Proto* f, DumpState* D)
|
112
|
+
{
|
113
|
+
int i,n;
|
114
|
+
n= (D->strip) ? 0 : f->sizelineinfo;
|
115
|
+
DumpVector(f->lineinfo,n,sizeof(int),D);
|
116
|
+
n= (D->strip) ? 0 : f->sizelocvars;
|
117
|
+
DumpInt(n,D);
|
118
|
+
for (i=0; i<n; i++)
|
119
|
+
{
|
120
|
+
DumpString(f->locvars[i].varname,D);
|
121
|
+
DumpInt(f->locvars[i].startpc,D);
|
122
|
+
DumpInt(f->locvars[i].endpc,D);
|
123
|
+
}
|
124
|
+
n= (D->strip) ? 0 : f->sizeupvalues;
|
125
|
+
DumpInt(n,D);
|
126
|
+
for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
|
127
|
+
}
|
128
|
+
|
129
|
+
static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
|
130
|
+
{
|
131
|
+
DumpString((f->source==p || D->strip) ? NULL : f->source,D);
|
132
|
+
DumpInt(f->linedefined,D);
|
133
|
+
DumpInt(f->lastlinedefined,D);
|
134
|
+
DumpChar(f->nups,D);
|
135
|
+
DumpChar(f->numparams,D);
|
136
|
+
DumpChar(f->is_vararg,D);
|
137
|
+
DumpChar(f->maxstacksize,D);
|
138
|
+
DumpCode(f,D);
|
139
|
+
DumpConstants(f,D);
|
140
|
+
DumpDebug(f,D);
|
141
|
+
}
|
142
|
+
|
143
|
+
static void DumpHeader(DumpState* D)
|
144
|
+
{
|
145
|
+
char h[LUAC_HEADERSIZE];
|
146
|
+
luaU_header(h);
|
147
|
+
DumpBlock(h,LUAC_HEADERSIZE,D);
|
148
|
+
}
|
149
|
+
|
150
|
+
/*
|
151
|
+
** dump Lua function as precompiled chunk
|
152
|
+
*/
|
153
|
+
int luaU_dump (lua_State* L, const Proto* f, lua_Writer w, void* data, int strip)
|
154
|
+
{
|
155
|
+
DumpState D;
|
156
|
+
D.L=L;
|
157
|
+
D.writer=w;
|
158
|
+
D.data=data;
|
159
|
+
D.strip=strip;
|
160
|
+
D.status=0;
|
161
|
+
DumpHeader(&D);
|
162
|
+
DumpFunction(f,NULL,&D);
|
163
|
+
return D.status;
|
164
|
+
}
|
@@ -0,0 +1,174 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lfunc.c,v 2.12a 2005/12/22 16:19:56 roberto Exp $
|
3
|
+
** Auxiliary functions to manipulate prototypes and closures
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#include <stddef.h>
|
9
|
+
|
10
|
+
#define lfunc_c
|
11
|
+
#define LUA_CORE
|
12
|
+
|
13
|
+
#include "lua.h"
|
14
|
+
|
15
|
+
#include "lfunc.h"
|
16
|
+
#include "lgc.h"
|
17
|
+
#include "lmem.h"
|
18
|
+
#include "lobject.h"
|
19
|
+
#include "lstate.h"
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e) {
|
24
|
+
Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
|
25
|
+
luaC_link(L, obj2gco(c), LUA_TFUNCTION);
|
26
|
+
c->c.isC = 1;
|
27
|
+
c->c.env = e;
|
28
|
+
c->c.nupvalues = cast_byte(nelems);
|
29
|
+
return c;
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e) {
|
34
|
+
Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
|
35
|
+
luaC_link(L, obj2gco(c), LUA_TFUNCTION);
|
36
|
+
c->l.isC = 0;
|
37
|
+
c->l.env = e;
|
38
|
+
c->l.nupvalues = cast_byte(nelems);
|
39
|
+
while (nelems--) c->l.upvals[nelems] = NULL;
|
40
|
+
return c;
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
UpVal *luaF_newupval (lua_State *L) {
|
45
|
+
UpVal *uv = luaM_new(L, UpVal);
|
46
|
+
luaC_link(L, obj2gco(uv), LUA_TUPVAL);
|
47
|
+
uv->v = &uv->u.value;
|
48
|
+
setnilvalue(uv->v);
|
49
|
+
return uv;
|
50
|
+
}
|
51
|
+
|
52
|
+
|
53
|
+
UpVal *luaF_findupval (lua_State *L, StkId level) {
|
54
|
+
global_State *g = G(L);
|
55
|
+
GCObject **pp = &L->openupval;
|
56
|
+
UpVal *p;
|
57
|
+
UpVal *uv;
|
58
|
+
while (*pp != NULL && (p = ngcotouv(*pp))->v >= level) {
|
59
|
+
lua_assert(p->v != &p->u.value);
|
60
|
+
if (p->v == level) { /* found a corresponding upvalue? */
|
61
|
+
if (isdead(g, obj2gco(p))) /* is it dead? */
|
62
|
+
changewhite(obj2gco(p)); /* ressurect it */
|
63
|
+
return p;
|
64
|
+
}
|
65
|
+
pp = &p->next;
|
66
|
+
}
|
67
|
+
uv = luaM_new(L, UpVal); /* not found: create a new one */
|
68
|
+
uv->tt = LUA_TUPVAL;
|
69
|
+
uv->marked = luaC_white(g);
|
70
|
+
uv->v = level; /* current value lives in the stack */
|
71
|
+
uv->next = *pp; /* chain it in the proper position */
|
72
|
+
*pp = obj2gco(uv);
|
73
|
+
uv->u.l.prev = &g->uvhead; /* double link it in `uvhead' list */
|
74
|
+
uv->u.l.next = g->uvhead.u.l.next;
|
75
|
+
uv->u.l.next->u.l.prev = uv;
|
76
|
+
g->uvhead.u.l.next = uv;
|
77
|
+
lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
|
78
|
+
return uv;
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
static void unlinkupval (UpVal *uv) {
|
83
|
+
lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
|
84
|
+
uv->u.l.next->u.l.prev = uv->u.l.prev; /* remove from `uvhead' list */
|
85
|
+
uv->u.l.prev->u.l.next = uv->u.l.next;
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
void luaF_freeupval (lua_State *L, UpVal *uv) {
|
90
|
+
if (uv->v != &uv->u.value) /* is it open? */
|
91
|
+
unlinkupval(uv); /* remove from open list */
|
92
|
+
luaM_free(L, uv); /* free upvalue */
|
93
|
+
}
|
94
|
+
|
95
|
+
|
96
|
+
void luaF_close (lua_State *L, StkId level) {
|
97
|
+
UpVal *uv;
|
98
|
+
global_State *g = G(L);
|
99
|
+
while (L->openupval != NULL && (uv = ngcotouv(L->openupval))->v >= level) {
|
100
|
+
GCObject *o = obj2gco(uv);
|
101
|
+
lua_assert(!isblack(o) && uv->v != &uv->u.value);
|
102
|
+
L->openupval = uv->next; /* remove from `open' list */
|
103
|
+
if (isdead(g, o))
|
104
|
+
luaF_freeupval(L, uv); /* free upvalue */
|
105
|
+
else {
|
106
|
+
unlinkupval(uv);
|
107
|
+
setobj(L, &uv->u.value, uv->v);
|
108
|
+
uv->v = &uv->u.value; /* now current value lives here */
|
109
|
+
luaC_linkupval(L, uv); /* link upvalue into `gcroot' list */
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
Proto *luaF_newproto (lua_State *L) {
|
116
|
+
Proto *f = luaM_new(L, Proto);
|
117
|
+
luaC_link(L, obj2gco(f), LUA_TPROTO);
|
118
|
+
f->k = NULL;
|
119
|
+
f->sizek = 0;
|
120
|
+
f->p = NULL;
|
121
|
+
f->sizep = 0;
|
122
|
+
f->code = NULL;
|
123
|
+
f->sizecode = 0;
|
124
|
+
f->sizelineinfo = 0;
|
125
|
+
f->sizeupvalues = 0;
|
126
|
+
f->nups = 0;
|
127
|
+
f->upvalues = NULL;
|
128
|
+
f->numparams = 0;
|
129
|
+
f->is_vararg = 0;
|
130
|
+
f->maxstacksize = 0;
|
131
|
+
f->lineinfo = NULL;
|
132
|
+
f->sizelocvars = 0;
|
133
|
+
f->locvars = NULL;
|
134
|
+
f->linedefined = 0;
|
135
|
+
f->lastlinedefined = 0;
|
136
|
+
f->source = NULL;
|
137
|
+
return f;
|
138
|
+
}
|
139
|
+
|
140
|
+
|
141
|
+
void luaF_freeproto (lua_State *L, Proto *f) {
|
142
|
+
luaM_freearray(L, f->code, f->sizecode, Instruction);
|
143
|
+
luaM_freearray(L, f->p, f->sizep, Proto *);
|
144
|
+
luaM_freearray(L, f->k, f->sizek, TValue);
|
145
|
+
luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
|
146
|
+
luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
|
147
|
+
luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
|
148
|
+
luaM_free(L, f);
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
void luaF_freeclosure (lua_State *L, Closure *c) {
|
153
|
+
int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
|
154
|
+
sizeLclosure(c->l.nupvalues);
|
155
|
+
luaM_freemem(L, c, size);
|
156
|
+
}
|
157
|
+
|
158
|
+
|
159
|
+
/*
|
160
|
+
** Look for n-th local variable at line `line' in function `func'.
|
161
|
+
** Returns NULL if not found.
|
162
|
+
*/
|
163
|
+
const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
|
164
|
+
int i;
|
165
|
+
for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
|
166
|
+
if (pc < f->locvars[i].endpc) { /* is variable active? */
|
167
|
+
local_number--;
|
168
|
+
if (local_number == 0)
|
169
|
+
return getstr(f->locvars[i].varname);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
return NULL; /* not found */
|
173
|
+
}
|
174
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lfunc.h,v 2.4 2005/04/25 19:24:10 roberto Exp $
|
3
|
+
** Auxiliary functions to manipulate prototypes and closures
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lfunc_h
|
8
|
+
#define lfunc_h
|
9
|
+
|
10
|
+
|
11
|
+
#include "lobject.h"
|
12
|
+
|
13
|
+
|
14
|
+
#define sizeCclosure(n) (cast(int, sizeof(CClosure)) + \
|
15
|
+
cast(int, sizeof(TValue)*((n)-1)))
|
16
|
+
|
17
|
+
#define sizeLclosure(n) (cast(int, sizeof(LClosure)) + \
|
18
|
+
cast(int, sizeof(TValue *)*((n)-1)))
|
19
|
+
|
20
|
+
|
21
|
+
LUAI_FUNC Proto *luaF_newproto (lua_State *L);
|
22
|
+
LUAI_FUNC Closure *luaF_newCclosure (lua_State *L, int nelems, Table *e);
|
23
|
+
LUAI_FUNC Closure *luaF_newLclosure (lua_State *L, int nelems, Table *e);
|
24
|
+
LUAI_FUNC UpVal *luaF_newupval (lua_State *L);
|
25
|
+
LUAI_FUNC UpVal *luaF_findupval (lua_State *L, StkId level);
|
26
|
+
LUAI_FUNC void luaF_close (lua_State *L, StkId level);
|
27
|
+
LUAI_FUNC void luaF_freeproto (lua_State *L, Proto *f);
|
28
|
+
LUAI_FUNC void luaF_freeclosure (lua_State *L, Closure *c);
|
29
|
+
LUAI_FUNC void luaF_freeupval (lua_State *L, UpVal *uv);
|
30
|
+
LUAI_FUNC const char *luaF_getlocalname (const Proto *func, int local_number,
|
31
|
+
int pc);
|
32
|
+
|
33
|
+
|
34
|
+
#endif
|