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,695 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lua.c,v 1.160 2006/06/02 15:34:00 roberto Exp $
|
3
|
+
** Lua stand-alone interpreter
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#include <signal.h>
|
8
|
+
#include <stdio.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
|
12
|
+
#define lua_c
|
13
|
+
|
14
|
+
#include "lua.h"
|
15
|
+
|
16
|
+
#include "lauxlib.h"
|
17
|
+
#include "lualib.h"
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
static lua_State *globalL = NULL;
|
22
|
+
|
23
|
+
static const char *progname = LUA_PROGNAME;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
static void lstop (lua_State *L, lua_Debug *ar) {
|
28
|
+
(void)ar; /* unused arg. */
|
29
|
+
lua_sethook(L, NULL, 0, 0);
|
30
|
+
luaL_error(L, "interrupted!");
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
static void laction (int i) {
|
35
|
+
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
|
36
|
+
terminate process (default action) */
|
37
|
+
lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
static void print_usage (void) {
|
42
|
+
fprintf(stderr,
|
43
|
+
"usage: %s [options] [script [args]].\n"
|
44
|
+
"Available options are:\n"
|
45
|
+
" -e stat execute string " LUA_QL("stat") "\n"
|
46
|
+
" -l name require library " LUA_QL("name") "\n"
|
47
|
+
" -i enter interactive mode after executing " LUA_QL("script") "\n"
|
48
|
+
" -v show version information\n"
|
49
|
+
" -- stop handling options\n"
|
50
|
+
" - execute stdin and stop handling options\n"
|
51
|
+
,
|
52
|
+
progname);
|
53
|
+
fflush(stderr);
|
54
|
+
}
|
55
|
+
|
56
|
+
|
57
|
+
static void l_message (const char *pname, const char *msg) {
|
58
|
+
if (pname) fprintf(stderr, "%s: ", pname);
|
59
|
+
fprintf(stderr, "%s\n", msg);
|
60
|
+
fflush(stderr);
|
61
|
+
}
|
62
|
+
|
63
|
+
|
64
|
+
static int report (lua_State *L, int status) {
|
65
|
+
if (status && !lua_isnil(L, -1)) {
|
66
|
+
const char *msg = lua_tostring(L, -1);
|
67
|
+
if (msg == NULL) msg = "(error object is not a string)";
|
68
|
+
l_message(progname, msg);
|
69
|
+
lua_pop(L, 1);
|
70
|
+
}
|
71
|
+
return status;
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
static int traceback (lua_State *L) {
|
76
|
+
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
77
|
+
if (!lua_istable(L, -1)) {
|
78
|
+
lua_pop(L, 1);
|
79
|
+
return 1;
|
80
|
+
}
|
81
|
+
lua_getfield(L, -1, "traceback");
|
82
|
+
if (!lua_isfunction(L, -1)) {
|
83
|
+
lua_pop(L, 2);
|
84
|
+
return 1;
|
85
|
+
}
|
86
|
+
lua_pushvalue(L, 1); /* pass error message */
|
87
|
+
lua_pushinteger(L, 2); /* skip this function and traceback */
|
88
|
+
lua_call(L, 2, 1); /* call debug.traceback */
|
89
|
+
return 1;
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
static int docall (lua_State *L, int narg, int clear) {
|
94
|
+
int status;
|
95
|
+
int base = lua_gettop(L) - narg; /* function index */
|
96
|
+
lua_pushcfunction(L, traceback); /* push traceback function */
|
97
|
+
lua_insert(L, base); /* put it under chunk and args */
|
98
|
+
signal(SIGINT, laction);
|
99
|
+
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
|
100
|
+
signal(SIGINT, SIG_DFL);
|
101
|
+
lua_remove(L, base); /* remove traceback function */
|
102
|
+
/* force a complete garbage collection in case of errors */
|
103
|
+
if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
|
104
|
+
return status;
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
static void print_version (void) {
|
109
|
+
l_message(NULL, LUA_RELEASE " " LUA_COPYRIGHT);
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static int getargs (lua_State *L, char **argv, int n) {
|
114
|
+
int narg;
|
115
|
+
int i;
|
116
|
+
int argc = 0;
|
117
|
+
while (argv[argc]) argc++; /* count total number of arguments */
|
118
|
+
narg = argc - (n + 1); /* number of arguments to the script */
|
119
|
+
luaL_checkstack(L, narg + 3, "too many arguments to script");
|
120
|
+
for (i=n+1; i < argc; i++)
|
121
|
+
lua_pushstring(L, argv[i]);
|
122
|
+
lua_createtable(L, narg, n + 1);
|
123
|
+
for (i=0; i < argc; i++) {
|
124
|
+
lua_pushstring(L, argv[i]);
|
125
|
+
lua_rawseti(L, -2, i - n);
|
126
|
+
}
|
127
|
+
return narg;
|
128
|
+
}
|
129
|
+
|
130
|
+
|
131
|
+
static int dofile (lua_State *L, const char *name) {
|
132
|
+
int status = luaL_loadfile(L, name) || docall(L, 0, 1);
|
133
|
+
return report(L, status);
|
134
|
+
}
|
135
|
+
|
136
|
+
|
137
|
+
static int dostring (lua_State *L, const char *s, const char *name) {
|
138
|
+
int status = luaL_loadbuffer(L, s, strlen(s), name) || docall(L, 0, 1);
|
139
|
+
return report(L, status);
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
static int dolibrary (lua_State *L, const char *name) {
|
144
|
+
lua_getglobal(L, "require");
|
145
|
+
lua_pushstring(L, name);
|
146
|
+
return report(L, lua_pcall(L, 1, 0, 0));
|
147
|
+
}
|
148
|
+
|
149
|
+
|
150
|
+
static const char *get_prompt (lua_State *L, int firstline) {
|
151
|
+
const char *p;
|
152
|
+
lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2");
|
153
|
+
p = lua_tostring(L, -1);
|
154
|
+
if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2);
|
155
|
+
lua_pop(L, 1); /* remove global */
|
156
|
+
return p;
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
static int incomplete (lua_State *L, int status) {
|
161
|
+
if (status == LUA_ERRSYNTAX) {
|
162
|
+
size_t lmsg;
|
163
|
+
const char *msg = lua_tolstring(L, -1, &lmsg);
|
164
|
+
const char *tp = msg + lmsg - (sizeof(LUA_QL("<eof>")) - 1);
|
165
|
+
if (strstr(msg, LUA_QL("<eof>")) == tp) {
|
166
|
+
lua_pop(L, 1);
|
167
|
+
return 1;
|
168
|
+
}
|
169
|
+
}
|
170
|
+
return 0; /* else... */
|
171
|
+
}
|
172
|
+
|
173
|
+
|
174
|
+
static int pushline (lua_State *L, int firstline) {
|
175
|
+
char buffer[LUA_MAXINPUT];
|
176
|
+
char *b = buffer;
|
177
|
+
size_t l;
|
178
|
+
const char *prmt = get_prompt(L, firstline);
|
179
|
+
if (lua_readline(L, b, prmt) == 0)
|
180
|
+
return 0; /* no input */
|
181
|
+
l = strlen(b);
|
182
|
+
if (l > 0 && b[l-1] == '\n') /* line ends with newline? */
|
183
|
+
b[l-1] = '\0'; /* remove it */
|
184
|
+
if (firstline && b[0] == '=') /* first line starts with `=' ? */
|
185
|
+
lua_pushfstring(L, "return %s", b+1); /* change it to `return' */
|
186
|
+
else
|
187
|
+
lua_pushstring(L, b);
|
188
|
+
lua_freeline(L, b);
|
189
|
+
return 1;
|
190
|
+
}
|
191
|
+
|
192
|
+
|
193
|
+
static int loadline (lua_State *L) {
|
194
|
+
int status;
|
195
|
+
lua_settop(L, 0);
|
196
|
+
if (!pushline(L, 1))
|
197
|
+
return -1; /* no input */
|
198
|
+
for (;;) { /* repeat until gets a complete line */
|
199
|
+
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
|
200
|
+
if (!incomplete(L, status)) break; /* cannot try to add lines? */
|
201
|
+
if (!pushline(L, 0)) /* no more input? */
|
202
|
+
return -1;
|
203
|
+
lua_pushliteral(L, "\n"); /* add a new line... */
|
204
|
+
lua_insert(L, -2); /* ...between the two lines */
|
205
|
+
lua_concat(L, 3); /* join them */
|
206
|
+
}
|
207
|
+
lua_saveline(L, 1);
|
208
|
+
lua_remove(L, 1); /* remove line */
|
209
|
+
return status;
|
210
|
+
}
|
211
|
+
|
212
|
+
|
213
|
+
static void dotty (lua_State *L) {
|
214
|
+
int status;
|
215
|
+
const char *oldprogname = progname;
|
216
|
+
progname = NULL;
|
217
|
+
while ((status = loadline(L)) != -1) {
|
218
|
+
if (status == 0) status = docall(L, 0, 0);
|
219
|
+
report(L, status);
|
220
|
+
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
221
|
+
lua_getglobal(L, "print");
|
222
|
+
lua_insert(L, 1);
|
223
|
+
if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != 0)
|
224
|
+
l_message(progname, lua_pushfstring(L,
|
225
|
+
"error calling " LUA_QL("print") " (%s)",
|
226
|
+
lua_tostring(L, -1)));
|
227
|
+
}
|
228
|
+
}
|
229
|
+
lua_settop(L, 0); /* clear stack */
|
230
|
+
fputs("\n", stdout);
|
231
|
+
fflush(stdout);
|
232
|
+
progname = oldprogname;
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
static int handle_script (lua_State *L, char **argv, int n) {
|
237
|
+
int status;
|
238
|
+
const char *fname;
|
239
|
+
int narg = getargs(L, argv, n); /* collect arguments */
|
240
|
+
lua_setglobal(L, "arg");
|
241
|
+
fname = argv[n];
|
242
|
+
if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0)
|
243
|
+
fname = NULL; /* stdin */
|
244
|
+
status = luaL_loadfile(L, fname);
|
245
|
+
lua_insert(L, -(narg+1));
|
246
|
+
if (status == 0)
|
247
|
+
status = docall(L, narg, 0);
|
248
|
+
else
|
249
|
+
lua_pop(L, narg);
|
250
|
+
return report(L, status);
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
/* check that argument has no extra characters at the end */
|
255
|
+
#define notail(x) {if ((x)[2] != '\0') return -1;}
|
256
|
+
|
257
|
+
|
258
|
+
static int collectargs (char **argv, int *pi, int *pv, int *pe) {
|
259
|
+
int i;
|
260
|
+
for (i = 1; argv[i] != NULL; i++) {
|
261
|
+
if (argv[i][0] != '-') /* not an option? */
|
262
|
+
return i;
|
263
|
+
switch (argv[i][1]) { /* option */
|
264
|
+
case '-':
|
265
|
+
notail(argv[i]);
|
266
|
+
return (argv[i+1] != NULL ? i+1 : 0);
|
267
|
+
case '\0':
|
268
|
+
return i;
|
269
|
+
case 'i':
|
270
|
+
notail(argv[i]);
|
271
|
+
*pi = 1; /* go through */
|
272
|
+
case 'v':
|
273
|
+
notail(argv[i]);
|
274
|
+
*pv = 1;
|
275
|
+
break;
|
276
|
+
case 'e':
|
277
|
+
*pe = 1; /* go through */
|
278
|
+
case 'l':
|
279
|
+
if (argv[i][2] == '\0') {
|
280
|
+
i++;
|
281
|
+
if (argv[i] == NULL) return -1;
|
282
|
+
}
|
283
|
+
break;
|
284
|
+
default: return -1; /* invalid option */
|
285
|
+
}
|
286
|
+
}
|
287
|
+
return 0;
|
288
|
+
}
|
289
|
+
|
290
|
+
|
291
|
+
static int runargs (lua_State *L, char **argv, int n) {
|
292
|
+
int i;
|
293
|
+
for (i = 1; i < n; i++) {
|
294
|
+
if (argv[i] == NULL) continue;
|
295
|
+
lua_assert(argv[i][0] == '-');
|
296
|
+
switch (argv[i][1]) { /* option */
|
297
|
+
case 'e': {
|
298
|
+
const char *chunk = argv[i] + 2;
|
299
|
+
if (*chunk == '\0') chunk = argv[++i];
|
300
|
+
lua_assert(chunk != NULL);
|
301
|
+
if (dostring(L, chunk, "=(command line)") != 0)
|
302
|
+
return 1;
|
303
|
+
break;
|
304
|
+
}
|
305
|
+
case 'l': {
|
306
|
+
const char *filename = argv[i] + 2;
|
307
|
+
if (*filename == '\0') filename = argv[++i];
|
308
|
+
lua_assert(filename != NULL);
|
309
|
+
if (dolibrary(L, filename))
|
310
|
+
return 1; /* stop if file fails */
|
311
|
+
break;
|
312
|
+
}
|
313
|
+
default: break;
|
314
|
+
}
|
315
|
+
}
|
316
|
+
return 0;
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
static int handle_luainit (lua_State *L) {
|
321
|
+
const char *init = getenv(LUA_INIT);
|
322
|
+
if (init == NULL) return 0; /* status OK */
|
323
|
+
else if (init[0] == '@')
|
324
|
+
return dofile(L, init+1);
|
325
|
+
else
|
326
|
+
return dostring(L, init, "=" LUA_INIT);
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
struct Smain {
|
331
|
+
int argc;
|
332
|
+
char **argv;
|
333
|
+
int status;
|
334
|
+
};
|
335
|
+
|
336
|
+
|
337
|
+
static int pmain (lua_State *L) {
|
338
|
+
struct Smain *s = (struct Smain *)lua_touserdata(L, 1);
|
339
|
+
char **argv = s->argv;
|
340
|
+
int script;
|
341
|
+
int has_i = 0, has_v = 0, has_e = 0;
|
342
|
+
globalL = L;
|
343
|
+
if (argv[0] && argv[0][0]) progname = argv[0];
|
344
|
+
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
|
345
|
+
luaL_openlibs(L); /* open libraries */
|
346
|
+
lua_gc(L, LUA_GCRESTART, 0);
|
347
|
+
s->status = handle_luainit(L);
|
348
|
+
if (s->status != 0) return 0;
|
349
|
+
script = collectargs(argv, &has_i, &has_v, &has_e);
|
350
|
+
if (script < 0) { /* invalid args? */
|
351
|
+
print_usage();
|
352
|
+
s->status = 1;
|
353
|
+
return 0;
|
354
|
+
}
|
355
|
+
if (has_v) print_version();
|
356
|
+
s->status = runargs(L, argv, (script > 0) ? script : s->argc);
|
357
|
+
if (s->status != 0) return 0;
|
358
|
+
if (script)
|
359
|
+
s->status = handle_script(L, argv, script);
|
360
|
+
if (s->status != 0) return 0;
|
361
|
+
if (has_i)
|
362
|
+
dotty(L);
|
363
|
+
else if (script == 0 && !has_e && !has_v) {
|
364
|
+
if (lua_stdin_is_tty()) {
|
365
|
+
print_version();
|
366
|
+
dotty(L);
|
367
|
+
}
|
368
|
+
else dofile(L, NULL); /* executes stdin as a file */
|
369
|
+
}
|
370
|
+
return 0;
|
371
|
+
}
|
372
|
+
// ======================================================================================================================
|
373
|
+
// ======================================================================================================================
|
374
|
+
|
375
|
+
#include "matrix.h"
|
376
|
+
|
377
|
+
#include "lua_cpp_helper.h"
|
378
|
+
|
379
|
+
|
380
|
+
using namespace dub;
|
381
|
+
|
382
|
+
|
383
|
+
/* ============================ Constructors ====================== */
|
384
|
+
|
385
|
+
|
386
|
+
/** dub::Matrix::Matrix()
|
387
|
+
* app/include/matrix.h:14
|
388
|
+
*/
|
389
|
+
static int Matrix_Matrix1(lua_State *L) {
|
390
|
+
Matrix * retval__ = new Matrix();
|
391
|
+
lua_pushclass<Matrix>(L, retval__, "dub.Matrix");
|
392
|
+
return 1;
|
393
|
+
}
|
394
|
+
|
395
|
+
|
396
|
+
/** dub::Matrix::Matrix(int rows, int cols)
|
397
|
+
* app/include/matrix.h:16
|
398
|
+
*/
|
399
|
+
static int Matrix_Matrix2(lua_State *L) {
|
400
|
+
int rows = luaL_checkint (L, 1);
|
401
|
+
int cols = luaL_checkint (L, 2);
|
402
|
+
Matrix * retval__ = new Matrix(rows, cols);
|
403
|
+
lua_pushclass<Matrix>(L, retval__, "dub.Matrix");
|
404
|
+
return 1;
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
/** Overloaded function chooser for Matrix(...) */
|
410
|
+
static int Matrix_Matrix(lua_State *L) {
|
411
|
+
int type__ = lua_type(L, 1);
|
412
|
+
if (type__ == LUA_TNUMBER) {
|
413
|
+
return Matrix_Matrix2(L);
|
414
|
+
} else if (type__ == LUA_TNONE) {
|
415
|
+
return Matrix_Matrix1(L);
|
416
|
+
} else {
|
417
|
+
// use any to raise errors
|
418
|
+
return Matrix_Matrix1(L);
|
419
|
+
}
|
420
|
+
}
|
421
|
+
|
422
|
+
/* ============================ Destructor ====================== */
|
423
|
+
|
424
|
+
static int Matrix_destructor(lua_State *L) {
|
425
|
+
Matrix **userdata = (Matrix**)luaL_checkudata(L, 1, "dub.Matrix");
|
426
|
+
if (*userdata) delete *userdata;
|
427
|
+
*userdata = NULL;
|
428
|
+
return 0;
|
429
|
+
}
|
430
|
+
|
431
|
+
/* ============================ tostring ====================== */
|
432
|
+
|
433
|
+
static int Matrix__tostring(lua_State *L) {
|
434
|
+
Matrix **userdata = (Matrix**)luaL_checkudata(L, 1, "dub.Matrix");
|
435
|
+
lua_pushfstring(L, "dub.Matrix: %p", *userdata);
|
436
|
+
return 1;
|
437
|
+
}
|
438
|
+
|
439
|
+
/* ============================ Member Methods ====================== */
|
440
|
+
|
441
|
+
|
442
|
+
/** double dub::Matrix::cols()
|
443
|
+
* app/include/matrix.h:29
|
444
|
+
*/
|
445
|
+
static int Matrix_cols(lua_State *L) {
|
446
|
+
Matrix *self__ = *((Matrix**)luaL_checkudata(L, 1, "dub.Matrix"));
|
447
|
+
lua_remove(L, 1);
|
448
|
+
double retval__ = self__->cols();
|
449
|
+
lua_pushnumber(L, retval__);
|
450
|
+
return 1;
|
451
|
+
}
|
452
|
+
|
453
|
+
|
454
|
+
/** double dub::Matrix::rows()
|
455
|
+
* app/include/matrix.h:33
|
456
|
+
*/
|
457
|
+
static int Matrix_rows(lua_State *L) {
|
458
|
+
Matrix *self__ = *((Matrix**)luaL_checkudata(L, 1, "dub.Matrix"));
|
459
|
+
lua_remove(L, 1);
|
460
|
+
double retval__ = self__->rows();
|
461
|
+
lua_pushnumber(L, retval__);
|
462
|
+
return 1;
|
463
|
+
}
|
464
|
+
|
465
|
+
|
466
|
+
/** size_t dub::Matrix::size()
|
467
|
+
* app/include/matrix.h:25
|
468
|
+
*/
|
469
|
+
static int Matrix_size(lua_State *L) {
|
470
|
+
Matrix *self__ = *((Matrix**)luaL_checkudata(L, 1, "dub.Matrix"));
|
471
|
+
lua_remove(L, 1);
|
472
|
+
size_t retval__ = self__->size();
|
473
|
+
lua_pushnumber(L, retval__);
|
474
|
+
return 1;
|
475
|
+
}
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
/* ============================ Lua Registration ====================== */
|
481
|
+
|
482
|
+
static const struct luaL_Reg Matrix_member_methods[] = {
|
483
|
+
{"cols" , Matrix_cols},
|
484
|
+
{"rows" , Matrix_rows},
|
485
|
+
{"size" , Matrix_size},
|
486
|
+
{"__tostring" , Matrix__tostring},
|
487
|
+
{"__gc" , Matrix_destructor},
|
488
|
+
{NULL, NULL},
|
489
|
+
};
|
490
|
+
|
491
|
+
static const struct luaL_Reg Matrix_namespace_methods[] = {
|
492
|
+
{"Matrix" , Matrix_Matrix},
|
493
|
+
{NULL, NULL},
|
494
|
+
};
|
495
|
+
|
496
|
+
static void luaopen_dub_Matrix(lua_State *L) {
|
497
|
+
// Create the metatable which will contain all the member methods
|
498
|
+
luaL_newmetatable(L, "dub.Matrix"); // "dub.Matrix"
|
499
|
+
|
500
|
+
// metatable.__index = metatable (find methods in the table itself)
|
501
|
+
lua_pushvalue(L, -1);
|
502
|
+
lua_setfield(L, -2, "__index");
|
503
|
+
|
504
|
+
// register member methods
|
505
|
+
luaL_register(L, NULL, Matrix_member_methods); // dub_Matrix_member_methods
|
506
|
+
|
507
|
+
// register class methods in a global table like "dub.Matrix"
|
508
|
+
luaL_register(L, "dub", Matrix_namespace_methods); // dub_Matrix_class_methods
|
509
|
+
}
|
510
|
+
#include "matrix.h"
|
511
|
+
|
512
|
+
#include "lua_cpp_helper.h"
|
513
|
+
|
514
|
+
|
515
|
+
using namespace dub;
|
516
|
+
|
517
|
+
|
518
|
+
/* ============================ Constructors ====================== */
|
519
|
+
|
520
|
+
|
521
|
+
/** dub::FloatMat::FloatMat()
|
522
|
+
* app/include/matrix.h:62
|
523
|
+
*/
|
524
|
+
static int FloatMat_FloatMat1(lua_State *L) {
|
525
|
+
FloatMat * retval__ = new FloatMat();
|
526
|
+
lua_pushclass<FloatMat>(L, retval__, "dub.FloatMat");
|
527
|
+
return 1;
|
528
|
+
}
|
529
|
+
|
530
|
+
|
531
|
+
/** dub::FloatMat::FloatMat(int rows, int cols)
|
532
|
+
* app/include/matrix.h:64
|
533
|
+
*/
|
534
|
+
static int FloatMat_FloatMat2(lua_State *L) {
|
535
|
+
int rows = luaL_checkint (L, 1);
|
536
|
+
int cols = luaL_checkint (L, 2);
|
537
|
+
FloatMat * retval__ = new FloatMat(rows, cols);
|
538
|
+
lua_pushclass<FloatMat>(L, retval__, "dub.FloatMat");
|
539
|
+
return 1;
|
540
|
+
}
|
541
|
+
|
542
|
+
|
543
|
+
|
544
|
+
/** Overloaded function chooser for FloatMat(...) */
|
545
|
+
static int FloatMat_FloatMat(lua_State *L) {
|
546
|
+
int type__ = lua_type(L, 1);
|
547
|
+
if (type__ == LUA_TNUMBER) {
|
548
|
+
return FloatMat_FloatMat2(L);
|
549
|
+
} else if (type__ == LUA_TNONE) {
|
550
|
+
return FloatMat_FloatMat1(L);
|
551
|
+
} else {
|
552
|
+
// use any to raise errors
|
553
|
+
return FloatMat_FloatMat1(L);
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
/* ============================ Destructor ====================== */
|
558
|
+
|
559
|
+
static int FloatMat_destructor(lua_State *L) {
|
560
|
+
FloatMat **userdata = (FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat");
|
561
|
+
if (*userdata) delete *userdata;
|
562
|
+
*userdata = NULL;
|
563
|
+
return 0;
|
564
|
+
}
|
565
|
+
|
566
|
+
/* ============================ tostring ====================== */
|
567
|
+
|
568
|
+
static int FloatMat__tostring(lua_State *L) {
|
569
|
+
FloatMat **userdata = (FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat");
|
570
|
+
lua_pushfstring(L, "dub.FloatMat: %p", *userdata);
|
571
|
+
return 1;
|
572
|
+
}
|
573
|
+
|
574
|
+
/* ============================ Member Methods ====================== */
|
575
|
+
|
576
|
+
|
577
|
+
/** size_t dub::FloatMat::cols()
|
578
|
+
* app/include/matrix.h:77
|
579
|
+
*/
|
580
|
+
static int FloatMat_cols(lua_State *L) {
|
581
|
+
FloatMat *self__ = *((FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat"));
|
582
|
+
lua_remove(L, 1);
|
583
|
+
size_t retval__ = self__->cols();
|
584
|
+
lua_pushnumber(L, retval__);
|
585
|
+
return 1;
|
586
|
+
}
|
587
|
+
|
588
|
+
|
589
|
+
/** void dub::FloatMat::fill(T value)
|
590
|
+
* app/include/matrix.h:85
|
591
|
+
*/
|
592
|
+
static int FloatMat_fill(lua_State *L) {
|
593
|
+
FloatMat *self__ = *((FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat"));
|
594
|
+
lua_remove(L, 1);
|
595
|
+
float value = luaL_checknumber(L, 1);
|
596
|
+
self__->fill(value);
|
597
|
+
return 0;
|
598
|
+
}
|
599
|
+
|
600
|
+
|
601
|
+
/** T dub::FloatMat::get(size_t row, size_t col)
|
602
|
+
* app/include/matrix.h:89
|
603
|
+
*/
|
604
|
+
static int FloatMat_get(lua_State *L) {
|
605
|
+
FloatMat *self__ = *((FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat"));
|
606
|
+
lua_remove(L, 1);
|
607
|
+
size_t row = luaL_checknumber(L, 1);
|
608
|
+
size_t col = luaL_checknumber(L, 2);
|
609
|
+
float retval__ = self__->get(row, col);
|
610
|
+
lua_pushnumber(L, retval__);
|
611
|
+
return 1;
|
612
|
+
}
|
613
|
+
|
614
|
+
|
615
|
+
/** size_t dub::FloatMat::rows()
|
616
|
+
* app/include/matrix.h:81
|
617
|
+
*/
|
618
|
+
static int FloatMat_rows(lua_State *L) {
|
619
|
+
FloatMat *self__ = *((FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat"));
|
620
|
+
lua_remove(L, 1);
|
621
|
+
size_t retval__ = self__->rows();
|
622
|
+
lua_pushnumber(L, retval__);
|
623
|
+
return 1;
|
624
|
+
}
|
625
|
+
|
626
|
+
|
627
|
+
/** size_t dub::FloatMat::size()
|
628
|
+
* app/include/matrix.h:73
|
629
|
+
*/
|
630
|
+
static int FloatMat_size(lua_State *L) {
|
631
|
+
FloatMat *self__ = *((FloatMat**)luaL_checkudata(L, 1, "dub.FloatMat"));
|
632
|
+
lua_remove(L, 1);
|
633
|
+
size_t retval__ = self__->size();
|
634
|
+
lua_pushnumber(L, retval__);
|
635
|
+
return 1;
|
636
|
+
}
|
637
|
+
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
/* ============================ Lua Registration ====================== */
|
642
|
+
|
643
|
+
static const struct luaL_Reg FloatMat_member_methods[] = {
|
644
|
+
{"cols" , FloatMat_cols},
|
645
|
+
{"fill" , FloatMat_fill},
|
646
|
+
{"get" , FloatMat_get},
|
647
|
+
{"rows" , FloatMat_rows},
|
648
|
+
{"size" , FloatMat_size},
|
649
|
+
{"__tostring" , FloatMat__tostring},
|
650
|
+
{"__gc" , FloatMat_destructor},
|
651
|
+
{NULL, NULL},
|
652
|
+
};
|
653
|
+
|
654
|
+
static const struct luaL_Reg FloatMat_namespace_methods[] = {
|
655
|
+
{"FloatMat" , FloatMat_FloatMat},
|
656
|
+
{"FMatrix" , FloatMat_FloatMat},
|
657
|
+
{NULL, NULL},
|
658
|
+
};
|
659
|
+
|
660
|
+
static void luaopen_dub_FloatMat(lua_State *L) {
|
661
|
+
// Create the metatable which will contain all the member methods
|
662
|
+
luaL_newmetatable(L, "dub.FloatMat"); // "dub.Matrix"
|
663
|
+
|
664
|
+
// metatable.__index = metatable (find methods in the table itself)
|
665
|
+
lua_pushvalue(L, -1);
|
666
|
+
lua_setfield(L, -2, "__index");
|
667
|
+
|
668
|
+
// register member methods
|
669
|
+
luaL_register(L, NULL, FloatMat_member_methods); // dub_Matrix_member_methods
|
670
|
+
|
671
|
+
// register class methods in a global table like "dub.Matrix"
|
672
|
+
luaL_register(L, "dub", FloatMat_namespace_methods); // dub_Matrix_class_methods
|
673
|
+
}
|
674
|
+
|
675
|
+
|
676
|
+
// ======================================================================================================================
|
677
|
+
// ======================================================================================================================
|
678
|
+
int main (int argc, char **argv) {
|
679
|
+
int status;
|
680
|
+
struct Smain s;
|
681
|
+
lua_State *L = lua_open(); /* create state */
|
682
|
+
if (L == NULL) {
|
683
|
+
l_message(argv[0], "cannot create state: not enough memory");
|
684
|
+
return EXIT_FAILURE;
|
685
|
+
}
|
686
|
+
luaopen_dub_Matrix(L);
|
687
|
+
luaopen_dub_FloatMat(L);
|
688
|
+
s.argc = argc;
|
689
|
+
s.argv = argv;
|
690
|
+
status = lua_cpcall(L, &pmain, &s);
|
691
|
+
report(L, status);
|
692
|
+
lua_close(L);
|
693
|
+
return (status || s.status) ? EXIT_FAILURE : EXIT_SUCCESS;
|
694
|
+
}
|
695
|
+
|