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,36 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lvm.h,v 2.5 2005/08/22 18:54:49 roberto Exp $
|
3
|
+
** Lua virtual machine
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef lvm_h
|
8
|
+
#define lvm_h
|
9
|
+
|
10
|
+
|
11
|
+
#include "ldo.h"
|
12
|
+
#include "lobject.h"
|
13
|
+
#include "ltm.h"
|
14
|
+
|
15
|
+
|
16
|
+
#define tostring(L,o) ((ttype(o) == LUA_TSTRING) || (luaV_tostring(L, o)))
|
17
|
+
|
18
|
+
#define tonumber(o,n) (ttype(o) == LUA_TNUMBER || \
|
19
|
+
(((o) = luaV_tonumber(o,n)) != NULL))
|
20
|
+
|
21
|
+
#define equalobj(L,o1,o2) \
|
22
|
+
(ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2))
|
23
|
+
|
24
|
+
|
25
|
+
LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
|
26
|
+
LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2);
|
27
|
+
LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n);
|
28
|
+
LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj);
|
29
|
+
LUAI_FUNC void luaV_gettable (lua_State *L, const TValue *t, TValue *key,
|
30
|
+
StkId val);
|
31
|
+
LUAI_FUNC void luaV_settable (lua_State *L, const TValue *t, TValue *key,
|
32
|
+
StkId val);
|
33
|
+
LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls);
|
34
|
+
LUAI_FUNC void luaV_concat (lua_State *L, int total, int last);
|
35
|
+
|
36
|
+
#endif
|
@@ -0,0 +1,82 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lzio.c,v 1.31 2005/06/03 20:15:29 roberto Exp $
|
3
|
+
** a generic input stream interface
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#include <string.h>
|
9
|
+
|
10
|
+
#define lzio_c
|
11
|
+
#define LUA_CORE
|
12
|
+
|
13
|
+
#include "lua.h"
|
14
|
+
|
15
|
+
#include "llimits.h"
|
16
|
+
#include "lmem.h"
|
17
|
+
#include "lstate.h"
|
18
|
+
#include "lzio.h"
|
19
|
+
|
20
|
+
|
21
|
+
int luaZ_fill (ZIO *z) {
|
22
|
+
size_t size;
|
23
|
+
lua_State *L = z->L;
|
24
|
+
const char *buff;
|
25
|
+
lua_unlock(L);
|
26
|
+
buff = z->reader(L, z->data, &size);
|
27
|
+
lua_lock(L);
|
28
|
+
if (buff == NULL || size == 0) return EOZ;
|
29
|
+
z->n = size - 1;
|
30
|
+
z->p = buff;
|
31
|
+
return char2int(*(z->p++));
|
32
|
+
}
|
33
|
+
|
34
|
+
|
35
|
+
int luaZ_lookahead (ZIO *z) {
|
36
|
+
if (z->n == 0) {
|
37
|
+
if (luaZ_fill(z) == EOZ)
|
38
|
+
return EOZ;
|
39
|
+
else {
|
40
|
+
z->n++; /* luaZ_fill removed first byte; put back it */
|
41
|
+
z->p--;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
return char2int(*z->p);
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
|
49
|
+
z->L = L;
|
50
|
+
z->reader = reader;
|
51
|
+
z->data = data;
|
52
|
+
z->n = 0;
|
53
|
+
z->p = NULL;
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
/* --------------------------------------------------------------- read --- */
|
58
|
+
size_t luaZ_read (ZIO *z, void *b, size_t n) {
|
59
|
+
while (n) {
|
60
|
+
size_t m;
|
61
|
+
if (luaZ_lookahead(z) == EOZ)
|
62
|
+
return n; /* return number of missing bytes */
|
63
|
+
m = (n <= z->n) ? n : z->n; /* min. between n and z->n */
|
64
|
+
memcpy(b, z->p, m);
|
65
|
+
z->n -= m;
|
66
|
+
z->p += m;
|
67
|
+
b = (char *)b + m;
|
68
|
+
n -= m;
|
69
|
+
}
|
70
|
+
return 0;
|
71
|
+
}
|
72
|
+
|
73
|
+
/* ------------------------------------------------------------------------ */
|
74
|
+
char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n) {
|
75
|
+
if (n > buff->buffsize) {
|
76
|
+
if (n < LUA_MINBUFFER) n = LUA_MINBUFFER;
|
77
|
+
luaZ_resizebuffer(L, buff, n);
|
78
|
+
}
|
79
|
+
return buff->buffer;
|
80
|
+
}
|
81
|
+
|
82
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lzio.h,v 1.21 2005/05/17 19:49:15 roberto Exp $
|
3
|
+
** Buffered streams
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#ifndef lzio_h
|
9
|
+
#define lzio_h
|
10
|
+
|
11
|
+
#include "lua.h"
|
12
|
+
|
13
|
+
#include "lmem.h"
|
14
|
+
|
15
|
+
|
16
|
+
#define EOZ (-1) /* end of stream */
|
17
|
+
|
18
|
+
typedef struct Zio ZIO;
|
19
|
+
|
20
|
+
#define char2int(c) cast(int, cast(unsigned char, (c)))
|
21
|
+
|
22
|
+
#define zgetc(z) (((z)->n--)>0 ? char2int(*(z)->p++) : luaZ_fill(z))
|
23
|
+
|
24
|
+
typedef struct Mbuffer {
|
25
|
+
char *buffer;
|
26
|
+
size_t n;
|
27
|
+
size_t buffsize;
|
28
|
+
} Mbuffer;
|
29
|
+
|
30
|
+
#define luaZ_initbuffer(L, buff) ((buff)->buffer = NULL, (buff)->buffsize = 0)
|
31
|
+
|
32
|
+
#define luaZ_buffer(buff) ((buff)->buffer)
|
33
|
+
#define luaZ_sizebuffer(buff) ((buff)->buffsize)
|
34
|
+
#define luaZ_bufflen(buff) ((buff)->n)
|
35
|
+
|
36
|
+
#define luaZ_resetbuffer(buff) ((buff)->n = 0)
|
37
|
+
|
38
|
+
|
39
|
+
#define luaZ_resizebuffer(L, buff, size) \
|
40
|
+
(luaM_reallocvector(L, (buff)->buffer, (buff)->buffsize, size, char), \
|
41
|
+
(buff)->buffsize = size)
|
42
|
+
|
43
|
+
#define luaZ_freebuffer(L, buff) luaZ_resizebuffer(L, buff, 0)
|
44
|
+
|
45
|
+
|
46
|
+
LUAI_FUNC char *luaZ_openspace (lua_State *L, Mbuffer *buff, size_t n);
|
47
|
+
LUAI_FUNC void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader,
|
48
|
+
void *data);
|
49
|
+
LUAI_FUNC size_t luaZ_read (ZIO* z, void* b, size_t n); /* read next n bytes */
|
50
|
+
LUAI_FUNC int luaZ_lookahead (ZIO *z);
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
/* --------- Private Part ------------------ */
|
55
|
+
|
56
|
+
struct Zio {
|
57
|
+
size_t n; /* bytes still unread */
|
58
|
+
const char *p; /* current position in buffer */
|
59
|
+
lua_Reader reader;
|
60
|
+
void* data; /* additional data */
|
61
|
+
lua_State *L; /* Lua state (for reader) */
|
62
|
+
};
|
63
|
+
|
64
|
+
|
65
|
+
LUAI_FUNC int luaZ_fill (ZIO *z);
|
66
|
+
|
67
|
+
#endif
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#ifndef DOXY_GENERATOR_TEST_FIXTURES_APP_MATRIX_H_
|
2
|
+
#define DOXY_GENERATOR_TEST_FIXTURES_APP_MATRIX_H_
|
3
|
+
|
4
|
+
#include <cstring>
|
5
|
+
#include <stdlib.h> // malloc
|
6
|
+
|
7
|
+
|
8
|
+
/** @file */
|
9
|
+
|
10
|
+
namespace dub {
|
11
|
+
|
12
|
+
class Matrix {
|
13
|
+
public:
|
14
|
+
Matrix() : data_(NULL), rows_(0), cols_(0) {}
|
15
|
+
|
16
|
+
Matrix(int rows, int cols) : rows_(rows), cols_(cols) {
|
17
|
+
data_ = (double*)malloc(size() * sizeof(double));
|
18
|
+
}
|
19
|
+
|
20
|
+
~Matrix() {
|
21
|
+
if (data_) free(data_);
|
22
|
+
}
|
23
|
+
|
24
|
+
/** Return size of matrix (rows * cols). */
|
25
|
+
size_t size() {
|
26
|
+
return rows_ * cols_;
|
27
|
+
}
|
28
|
+
|
29
|
+
double cols() {
|
30
|
+
return cols_;
|
31
|
+
}
|
32
|
+
|
33
|
+
double rows() {
|
34
|
+
return rows_;
|
35
|
+
}
|
36
|
+
|
37
|
+
/** Dummy template based class method.
|
38
|
+
*/
|
39
|
+
template<class T>
|
40
|
+
T *give_me_tea() {
|
41
|
+
return new T();
|
42
|
+
}
|
43
|
+
|
44
|
+
operator size_t() {
|
45
|
+
return size();
|
46
|
+
}
|
47
|
+
|
48
|
+
private:
|
49
|
+
double *data_;
|
50
|
+
size_t rows_;
|
51
|
+
size_t cols_;
|
52
|
+
};
|
53
|
+
|
54
|
+
|
55
|
+
template<class T>
|
56
|
+
class TMat {
|
57
|
+
public:
|
58
|
+
TMat() : data_(NULL), rows_(0), cols_(0) {}
|
59
|
+
|
60
|
+
TMat(int rows, int cols) : rows_(rows), cols_(cols) {
|
61
|
+
data_ = (T*)malloc(size() * sizeof(T));
|
62
|
+
}
|
63
|
+
|
64
|
+
~TMat() {
|
65
|
+
if (data_) free(data_);
|
66
|
+
}
|
67
|
+
|
68
|
+
/** Return size of matrix (rows * cols). */
|
69
|
+
size_t size() {
|
70
|
+
return rows_ * cols_;
|
71
|
+
}
|
72
|
+
|
73
|
+
size_t cols() {
|
74
|
+
return cols_;
|
75
|
+
}
|
76
|
+
|
77
|
+
size_t rows() {
|
78
|
+
return rows_;
|
79
|
+
}
|
80
|
+
|
81
|
+
void fill(T value) {
|
82
|
+
// dummy
|
83
|
+
}
|
84
|
+
|
85
|
+
T get(size_t row, size_t col) {
|
86
|
+
return data_[row * cols_ + col];
|
87
|
+
}
|
88
|
+
|
89
|
+
private:
|
90
|
+
T *data_;
|
91
|
+
size_t rows_;
|
92
|
+
size_t cols_;
|
93
|
+
};
|
94
|
+
|
95
|
+
/** @var FloatMat
|
96
|
+
*/
|
97
|
+
typedef TMat<float> FloatMat;
|
98
|
+
typedef FloatMat FMatrix;
|
99
|
+
|
100
|
+
} // dub
|
101
|
+
|
102
|
+
#endif // DOXY_GENERATOR_TEST_FIXTURES_APP_MATRIX_H_
|
@@ -0,0 +1,227 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: print.c,v 1.55a 2006/05/31 13:30:05 lhf Exp $
|
3
|
+
** print bytecodes
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <ctype.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
|
10
|
+
#define luac_c
|
11
|
+
#define LUA_CORE
|
12
|
+
|
13
|
+
#include "ldebug.h"
|
14
|
+
#include "lobject.h"
|
15
|
+
#include "lopcodes.h"
|
16
|
+
#include "lundump.h"
|
17
|
+
|
18
|
+
#define PrintFunction luaU_print
|
19
|
+
|
20
|
+
#define Sizeof(x) ((int)sizeof(x))
|
21
|
+
#define VOID(p) ((const void*)(p))
|
22
|
+
|
23
|
+
static void PrintString(const TString* ts)
|
24
|
+
{
|
25
|
+
const char* s=getstr(ts);
|
26
|
+
size_t i,n=ts->tsv.len;
|
27
|
+
putchar('"');
|
28
|
+
for (i=0; i<n; i++)
|
29
|
+
{
|
30
|
+
int c=s[i];
|
31
|
+
switch (c)
|
32
|
+
{
|
33
|
+
case '"': printf("\\\""); break;
|
34
|
+
case '\\': printf("\\\\"); break;
|
35
|
+
case '\a': printf("\\a"); break;
|
36
|
+
case '\b': printf("\\b"); break;
|
37
|
+
case '\f': printf("\\f"); break;
|
38
|
+
case '\n': printf("\\n"); break;
|
39
|
+
case '\r': printf("\\r"); break;
|
40
|
+
case '\t': printf("\\t"); break;
|
41
|
+
case '\v': printf("\\v"); break;
|
42
|
+
default: if (isprint((unsigned char)c))
|
43
|
+
putchar(c);
|
44
|
+
else
|
45
|
+
printf("\\%03u",(unsigned char)c);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
putchar('"');
|
49
|
+
}
|
50
|
+
|
51
|
+
static void PrintConstant(const Proto* f, int i)
|
52
|
+
{
|
53
|
+
const TValue* o=&f->k[i];
|
54
|
+
switch (ttype(o))
|
55
|
+
{
|
56
|
+
case LUA_TNIL:
|
57
|
+
printf("nil");
|
58
|
+
break;
|
59
|
+
case LUA_TBOOLEAN:
|
60
|
+
printf(bvalue(o) ? "true" : "false");
|
61
|
+
break;
|
62
|
+
case LUA_TNUMBER:
|
63
|
+
printf(LUA_NUMBER_FMT,nvalue(o));
|
64
|
+
break;
|
65
|
+
case LUA_TSTRING:
|
66
|
+
PrintString(rawtsvalue(o));
|
67
|
+
break;
|
68
|
+
default: /* cannot happen */
|
69
|
+
printf("? type=%d",ttype(o));
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
static void PrintCode(const Proto* f)
|
75
|
+
{
|
76
|
+
const Instruction* code=f->code;
|
77
|
+
int pc,n=f->sizecode;
|
78
|
+
for (pc=0; pc<n; pc++)
|
79
|
+
{
|
80
|
+
Instruction i=code[pc];
|
81
|
+
OpCode o=GET_OPCODE(i);
|
82
|
+
int a=GETARG_A(i);
|
83
|
+
int b=GETARG_B(i);
|
84
|
+
int c=GETARG_C(i);
|
85
|
+
int bx=GETARG_Bx(i);
|
86
|
+
int sbx=GETARG_sBx(i);
|
87
|
+
int line=getline(f,pc);
|
88
|
+
printf("\t%d\t",pc+1);
|
89
|
+
if (line>0) printf("[%d]\t",line); else printf("[-]\t");
|
90
|
+
printf("%-9s\t",luaP_opnames[o]);
|
91
|
+
switch (getOpMode(o))
|
92
|
+
{
|
93
|
+
case iABC:
|
94
|
+
printf("%d",a);
|
95
|
+
if (getBMode(o)!=OpArgN) printf(" %d",ISK(b) ? (-1-INDEXK(b)) : b);
|
96
|
+
if (getCMode(o)!=OpArgN) printf(" %d",ISK(c) ? (-1-INDEXK(c)) : c);
|
97
|
+
break;
|
98
|
+
case iABx:
|
99
|
+
if (getBMode(o)==OpArgK) printf("%d %d",a,-1-bx); else printf("%d %d",a,bx);
|
100
|
+
break;
|
101
|
+
case iAsBx:
|
102
|
+
if (o==OP_JMP) printf("%d",sbx); else printf("%d %d",a,sbx);
|
103
|
+
break;
|
104
|
+
}
|
105
|
+
switch (o)
|
106
|
+
{
|
107
|
+
case OP_LOADK:
|
108
|
+
printf("\t; "); PrintConstant(f,bx);
|
109
|
+
break;
|
110
|
+
case OP_GETUPVAL:
|
111
|
+
case OP_SETUPVAL:
|
112
|
+
printf("\t; %s", (f->sizeupvalues>0) ? getstr(f->upvalues[b]) : "-");
|
113
|
+
break;
|
114
|
+
case OP_GETGLOBAL:
|
115
|
+
case OP_SETGLOBAL:
|
116
|
+
printf("\t; %s",svalue(&f->k[bx]));
|
117
|
+
break;
|
118
|
+
case OP_GETTABLE:
|
119
|
+
case OP_SELF:
|
120
|
+
if (ISK(c)) { printf("\t; "); PrintConstant(f,INDEXK(c)); }
|
121
|
+
break;
|
122
|
+
case OP_SETTABLE:
|
123
|
+
case OP_ADD:
|
124
|
+
case OP_SUB:
|
125
|
+
case OP_MUL:
|
126
|
+
case OP_DIV:
|
127
|
+
case OP_POW:
|
128
|
+
case OP_EQ:
|
129
|
+
case OP_LT:
|
130
|
+
case OP_LE:
|
131
|
+
if (ISK(b) || ISK(c))
|
132
|
+
{
|
133
|
+
printf("\t; ");
|
134
|
+
if (ISK(b)) PrintConstant(f,INDEXK(b)); else printf("-");
|
135
|
+
printf(" ");
|
136
|
+
if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
|
137
|
+
}
|
138
|
+
break;
|
139
|
+
case OP_JMP:
|
140
|
+
case OP_FORLOOP:
|
141
|
+
case OP_FORPREP:
|
142
|
+
printf("\t; to %d",sbx+pc+2);
|
143
|
+
break;
|
144
|
+
case OP_CLOSURE:
|
145
|
+
printf("\t; %p",VOID(f->p[bx]));
|
146
|
+
break;
|
147
|
+
case OP_SETLIST:
|
148
|
+
if (c==0) printf("\t; %d",(int)code[++pc]);
|
149
|
+
else printf("\t; %d",c);
|
150
|
+
break;
|
151
|
+
default:
|
152
|
+
break;
|
153
|
+
}
|
154
|
+
printf("\n");
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
#define SS(x) (x==1)?"":"s"
|
159
|
+
#define S(x) x,SS(x)
|
160
|
+
|
161
|
+
static void PrintHeader(const Proto* f)
|
162
|
+
{
|
163
|
+
const char* s=getstr(f->source);
|
164
|
+
if (*s=='@' || *s=='=')
|
165
|
+
s++;
|
166
|
+
else if (*s==LUA_SIGNATURE[0])
|
167
|
+
s="(bstring)";
|
168
|
+
else
|
169
|
+
s="(string)";
|
170
|
+
printf("\n%s <%s:%d,%d> (%d instruction%s, %d bytes at %p)\n",
|
171
|
+
(f->linedefined==0)?"main":"function",s,
|
172
|
+
f->linedefined,f->lastlinedefined,
|
173
|
+
S(f->sizecode),f->sizecode*Sizeof(Instruction),VOID(f));
|
174
|
+
printf("%d%s param%s, %d slot%s, %d upvalue%s, ",
|
175
|
+
f->numparams,f->is_vararg?"+":"",SS(f->numparams),
|
176
|
+
S(f->maxstacksize),S(f->nups));
|
177
|
+
printf("%d local%s, %d constant%s, %d function%s\n",
|
178
|
+
S(f->sizelocvars),S(f->sizek),S(f->sizep));
|
179
|
+
}
|
180
|
+
|
181
|
+
static void PrintConstants(const Proto* f)
|
182
|
+
{
|
183
|
+
int i,n=f->sizek;
|
184
|
+
printf("constants (%d) for %p:\n",n,VOID(f));
|
185
|
+
for (i=0; i<n; i++)
|
186
|
+
{
|
187
|
+
printf("\t%d\t",i+1);
|
188
|
+
PrintConstant(f,i);
|
189
|
+
printf("\n");
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
static void PrintLocals(const Proto* f)
|
194
|
+
{
|
195
|
+
int i,n=f->sizelocvars;
|
196
|
+
printf("locals (%d) for %p:\n",n,VOID(f));
|
197
|
+
for (i=0; i<n; i++)
|
198
|
+
{
|
199
|
+
printf("\t%d\t%s\t%d\t%d\n",
|
200
|
+
i,getstr(f->locvars[i].varname),f->locvars[i].startpc+1,f->locvars[i].endpc+1);
|
201
|
+
}
|
202
|
+
}
|
203
|
+
|
204
|
+
static void PrintUpvalues(const Proto* f)
|
205
|
+
{
|
206
|
+
int i,n=f->sizeupvalues;
|
207
|
+
printf("upvalues (%d) for %p:\n",n,VOID(f));
|
208
|
+
if (f->upvalues==NULL) return;
|
209
|
+
for (i=0; i<n; i++)
|
210
|
+
{
|
211
|
+
printf("\t%d\t%s\n",i,getstr(f->upvalues[i]));
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
void PrintFunction(const Proto* f, int full)
|
216
|
+
{
|
217
|
+
int i,n=f->sizep;
|
218
|
+
PrintHeader(f);
|
219
|
+
PrintCode(f);
|
220
|
+
if (full)
|
221
|
+
{
|
222
|
+
PrintConstants(f);
|
223
|
+
PrintLocals(f);
|
224
|
+
PrintUpvalues(f);
|
225
|
+
}
|
226
|
+
for (i=0; i<n; i++) PrintFunction(f->p[i],full);
|
227
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
These are simple tests for Lua. Some of them contain useful code.
|
2
|
+
They are meant to be run to make sure Lua is built correctly and also
|
3
|
+
to be read, to see how Lua programs look.
|
4
|
+
|
5
|
+
Here is a one-line summary of each program:
|
6
|
+
|
7
|
+
bisect.lua bisection method for solving non-linear equations
|
8
|
+
cf.lua temperature conversion table (celsius to farenheit)
|
9
|
+
echo.lua echo command line arguments
|
10
|
+
env.lua environment variables as automatic global variables
|
11
|
+
factorial.lua factorial without recursion
|
12
|
+
fib.lua fibonacci function with cache
|
13
|
+
fibfor.lua fibonacci numbers with coroutines and generators
|
14
|
+
globals.lua report global variable usage
|
15
|
+
hello.lua the first program in every language
|
16
|
+
life.lua Conway's Game of Life
|
17
|
+
luac.lua bare-bones luac
|
18
|
+
printf.lua an implementation of printf
|
19
|
+
readonly.lua make global variables readonly
|
20
|
+
sieve.lua the sieve of of Eratosthenes programmed with coroutines
|
21
|
+
sort.lua two implementations of a sort function
|
22
|
+
table.lua make table, grouping all data for the same item
|
23
|
+
trace-calls.lua trace calls
|
24
|
+
trace-globals.lua trace assigments to global variables
|
25
|
+
xd.lua hex dump
|
26
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
-- bisection method for solving non-linear equations
|
2
|
+
|
3
|
+
delta=1e-6 -- tolerance
|
4
|
+
|
5
|
+
function bisect(f,a,b,fa,fb)
|
6
|
+
local c=(a+b)/2
|
7
|
+
io.write(n," c=",c," a=",a," b=",b,"\n")
|
8
|
+
if c==a or c==b or math.abs(a-b)<delta then return c,b-a end
|
9
|
+
n=n+1
|
10
|
+
local fc=f(c)
|
11
|
+
if fa*fc<0 then return bisect(f,a,c,fa,fc) else return bisect(f,c,b,fc,fb) end
|
12
|
+
end
|
13
|
+
|
14
|
+
-- find root of f in the inverval [a,b]. needs f(a)*f(b)<0
|
15
|
+
function solve(f,a,b)
|
16
|
+
n=0
|
17
|
+
local z,e=bisect(f,a,b,f(a),f(b))
|
18
|
+
io.write(string.format("after %d steps, root is %.17g with error %.1e, f=%.1e\n",n,z,e,f(z)))
|
19
|
+
end
|
20
|
+
|
21
|
+
-- our function
|
22
|
+
function f(x)
|
23
|
+
return x*x*x-x-1
|
24
|
+
end
|
25
|
+
|
26
|
+
-- find zero in [1,2]
|
27
|
+
solve(f,1,2)
|
@@ -0,0 +1,16 @@
|
|
1
|
+
-- temperature conversion table (celsius to farenheit)
|
2
|
+
|
3
|
+
for c0=-20,50-1,10 do
|
4
|
+
io.write("C ")
|
5
|
+
for c=c0,c0+10-1 do
|
6
|
+
io.write(string.format("%3.0f ",c))
|
7
|
+
end
|
8
|
+
io.write("\n")
|
9
|
+
|
10
|
+
io.write("F ")
|
11
|
+
for c=c0,c0+10-1 do
|
12
|
+
f=(9/5)*c+32
|
13
|
+
io.write(string.format("%3.0f ",f))
|
14
|
+
end
|
15
|
+
io.write("\n\n")
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
-- function closures are powerful
|
2
|
+
|
3
|
+
-- traditional fixed-point operator from functional programming
|
4
|
+
Y = function (g)
|
5
|
+
local a = function (f) return f(f) end
|
6
|
+
return a(function (f)
|
7
|
+
return g(function (x)
|
8
|
+
local c=f(f)
|
9
|
+
return c(x)
|
10
|
+
end)
|
11
|
+
end)
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
-- factorial without recursion
|
16
|
+
F = function (f)
|
17
|
+
return function (n)
|
18
|
+
if n == 0 then return 1
|
19
|
+
else return n*f(n-1) end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
factorial = Y(F) -- factorial is the fixed point of F
|
24
|
+
|
25
|
+
-- now test it
|
26
|
+
function test(x)
|
27
|
+
io.write(x,"! = ",factorial(x),"\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
for n=0,16 do
|
31
|
+
test(n)
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
-- fibonacci function with cache
|
2
|
+
|
3
|
+
-- very inefficient fibonacci function
|
4
|
+
function fib(n)
|
5
|
+
N=N+1
|
6
|
+
if n<2 then
|
7
|
+
return n
|
8
|
+
else
|
9
|
+
return fib(n-1)+fib(n-2)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
-- a general-purpose value cache
|
14
|
+
function cache(f)
|
15
|
+
local c={}
|
16
|
+
return function (x)
|
17
|
+
local y=c[x]
|
18
|
+
if not y then
|
19
|
+
y=f(x)
|
20
|
+
c[x]=y
|
21
|
+
end
|
22
|
+
return y
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
-- run and time it
|
27
|
+
function test(s,f)
|
28
|
+
N=0
|
29
|
+
local c=os.clock()
|
30
|
+
local v=f(n)
|
31
|
+
local t=os.clock()-c
|
32
|
+
print(s,n,v,t,N)
|
33
|
+
end
|
34
|
+
|
35
|
+
n=arg[1] or 24 -- for other values, do lua fib.lua XX
|
36
|
+
n=tonumber(n)
|
37
|
+
print("","n","value","time","evals")
|
38
|
+
test("plain",fib)
|
39
|
+
fib=cache(fib)
|
40
|
+
test("cached",fib)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
-- reads luac listings and reports global variable usage
|
2
|
+
-- lines where a global is written to are marked with "*"
|
3
|
+
-- typical usage: luac -p -l file.lua | lua globals.lua | sort | lua table.lua
|
4
|
+
|
5
|
+
while 1 do
|
6
|
+
local s=io.read()
|
7
|
+
if s==nil then break end
|
8
|
+
local ok,_,l,op,g=string.find(s,"%[%-?(%d*)%]%s*([GS])ETGLOBAL.-;%s+(.*)$")
|
9
|
+
if ok then
|
10
|
+
if op=="S" then op="*" else op="" end
|
11
|
+
io.write(g,"\t",l,op,"\n")
|
12
|
+
end
|
13
|
+
end
|