candle 0.0.1
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.
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/VERSION +1 -0
- data/bin/candle +21 -0
- data/lib/candle.rb +68 -0
- data/lib/candle/command.rb +27 -0
- data/lib/candle/generators/actions.rb +183 -0
- data/lib/candle/generators/blank.rb +127 -0
- data/lib/candle/generators/cli.rb +55 -0
- data/lib/candle/generators/help.rb +47 -0
- data/lib/candle/generators/jam.rb +80 -0
- data/lib/candle/generators/lua/scripts/AppDelegate.lua +36 -0
- data/lib/candle/generators/lua/scripts/tests/init.lua +6 -0
- data/lib/candle/generators/lua/scripts/tests/someTest.lua +12 -0
- data/lib/candle/generators/lua/wax/ProtocolLoader.h +12 -0
- data/lib/candle/generators/lua/wax/bin/hammer +157 -0
- data/lib/candle/generators/lua/wax/bin/update-xibs +131 -0
- data/lib/candle/generators/lua/wax/bin/waxsim +0 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/compile-stdlib.sh +14 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/copy-scripts.sh +58 -0
- data/lib/candle/generators/lua/wax/lib/build-scripts/luac.lua +80 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGAffine/wax_CGTransform.m +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.h +12 -0
- data/lib/candle/generators/lua/wax/lib/extensions/CGContext/wax_CGContext.m +251 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.h +14 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http.m +240 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.h +54 -0
- data/lib/candle/generators/lua/wax/lib/extensions/HTTP/wax_http_connection.m +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.h +9 -0
- data/lib/candle/generators/lua/wax/lib/extensions/filesystem/wax_filesystem.m +273 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/Rakefile +10 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.c +304 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/wax_json.h +11 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl-1.0.9.tar.gz +0 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/api/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl.c +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.c +65 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_alloc.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.c +119 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_buf.h +73 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_bytestack.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_common.h +85 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.c +188 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_encode.h +50 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.c +322 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_gen.h +159 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.c +737 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_lex.h +133 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parse.h +193 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.c +448 -0
- data/lib/candle/generators/lua/wax/lib/extensions/json/yajl/yajl_parser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.c +1087 -0
- data/lib/candle/generators/lua/wax/lib/lua/lapi.h +16 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.c +652 -0
- data/lib/candle/generators/lua/wax/lib/lua/lauxlib.h +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lbaselib.c +653 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.c +839 -0
- data/lib/candle/generators/lua/wax/lib/lua/lcode.h +76 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldblib.c +397 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.c +638 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldebug.h +33 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.c +518 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldo.h +57 -0
- data/lib/candle/generators/lua/wax/lib/lua/ldump.c +164 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.c +174 -0
- data/lib/candle/generators/lua/wax/lib/lua/lfunc.h +34 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.c +711 -0
- data/lib/candle/generators/lua/wax/lib/lua/lgc.h +110 -0
- data/lib/candle/generators/lua/wax/lib/lua/linit.c +38 -0
- data/lib/candle/generators/lua/wax/lib/lua/liolib.c +553 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.c +461 -0
- data/lib/candle/generators/lua/wax/lib/lua/llex.h +81 -0
- data/lib/candle/generators/lua/wax/lib/lua/llimits.h +128 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmathlib.c +263 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.c +86 -0
- data/lib/candle/generators/lua/wax/lib/lua/lmem.h +49 -0
- data/lib/candle/generators/lua/wax/lib/lua/loadlib.c +666 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lobject.h +381 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.c +102 -0
- data/lib/candle/generators/lua/wax/lib/lua/lopcodes.h +268 -0
- data/lib/candle/generators/lua/wax/lib/lua/loslib.c +243 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.c +1339 -0
- data/lib/candle/generators/lua/wax/lib/lua/lparser.h +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.c +214 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstate.h +169 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.c +111 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstring.h +31 -0
- data/lib/candle/generators/lua/wax/lib/lua/lstrlib.c +869 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.c +588 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltable.h +40 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltablib.c +287 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.c +75 -0
- data/lib/candle/generators/lua/wax/lib/lua/ltm.h +54 -0
- data/lib/candle/generators/lua/wax/lib/lua/lua.h +388 -0
- data/lib/candle/generators/lua/wax/lib/lua/luaconf.h +753 -0
- data/lib/candle/generators/lua/wax/lib/lua/lualib.h +53 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.c +227 -0
- data/lib/candle/generators/lua/wax/lib/lua/lundump.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.c +763 -0
- data/lib/candle/generators/lua/wax/lib/lua/lvm.h +36 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.c +82 -0
- data/lib/candle/generators/lua/wax/lib/lua/lzio.h +67 -0
- data/lib/candle/generators/lua/wax/lib/lua/print.c +227 -0
- data/lib/candle/generators/lua/wax/lib/project.rake +159 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/enums.lua +396 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/http.lua +43 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/init.lua +4 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/number.lua +21 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/string.lua +97 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/ext/table.lua +165 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/WaxServer.lua +49 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/autoload.lua +10 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/base64.lua +64 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/bit.lua +274 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/cache.lua +73 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/callback.lua +22 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/frame.lua +76 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/init.lua +78 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/pickView.lua +54 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/helpers/time.lua +102 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/init.lua +18 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/init.lua +2 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luamock.lua +84 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/luaspec/luaspec.lua +377 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/repl.lua +9 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/structs.lua +11 -0
- data/lib/candle/generators/lua/wax/lib/stdlib/waxClass.lua +42 -0
- data/lib/candle/generators/lua/wax/lib/wax.h +16 -0
- data/lib/candle/generators/lua/wax/lib/wax.m +260 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.h +18 -0
- data/lib/candle/generators/lua/wax/lib/wax_class.m +190 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.h +20 -0
- data/lib/candle/generators/lua/wax/lib/wax_gc.m +56 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.h +102 -0
- data/lib/candle/generators/lua/wax/lib/wax_helpers.m +870 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.h +34 -0
- data/lib/candle/generators/lua/wax/lib/wax_instance.m +810 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.h +47 -0
- data/lib/candle/generators/lua/wax/lib/wax_server.m +252 -0
- data/lib/candle/generators/lua/wax/lib/wax_stdlib.h +3 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.h +26 -0
- data/lib/candle/generators/lua/wax/lib/wax_struct.m +335 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.pbxproj +836 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/WaxApplication.xcscheme +86 -0
- data/lib/candle/generators/templates/blank/WaxApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +22 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default-568h@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/Default@2x.png +0 -0
- data/lib/candle/generators/templates/blank/WaxApplication/ProtocolLoader.h +12 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Info.plist.tt +38 -0
- data/lib/candle/generators/templates/blank/WaxApplication/WaxApplication-Prefix.pch.tt +14 -0
- data/lib/candle/generators/templates/blank/WaxApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/candle/generators/templates/blank/WaxApplication/main.m.tt +20 -0
- data/lib/candle/tasks.rb +22 -0
- data/lib/candle/utility.rb +30 -0
- data/lib/candle/version.rb +9 -0
- data/lib/candle/view.rb +48 -0
- metadata +582 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: llex.h,v 1.58.1.1 2007/12/27 13:02:25 roberto Exp $
|
3
|
+
** Lexical Analyzer
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef llex_h
|
8
|
+
#define llex_h
|
9
|
+
|
10
|
+
#include "lobject.h"
|
11
|
+
#include "lzio.h"
|
12
|
+
|
13
|
+
|
14
|
+
#define FIRST_RESERVED 257
|
15
|
+
|
16
|
+
/* maximum length of a reserved word */
|
17
|
+
#define TOKEN_LEN (sizeof("function")/sizeof(char))
|
18
|
+
|
19
|
+
|
20
|
+
/*
|
21
|
+
* WARNING: if you change the order of this enumeration,
|
22
|
+
* grep "ORDER RESERVED"
|
23
|
+
*/
|
24
|
+
enum RESERVED {
|
25
|
+
/* terminal symbols denoted by reserved words */
|
26
|
+
TK_AND = FIRST_RESERVED, TK_BREAK,
|
27
|
+
TK_DO, TK_ELSE, TK_ELSEIF, TK_END, TK_FALSE, TK_FOR, TK_FUNCTION,
|
28
|
+
TK_IF, TK_IN, TK_LOCAL, TK_NIL, TK_NOT, TK_OR, TK_REPEAT,
|
29
|
+
TK_RETURN, TK_THEN, TK_TRUE, TK_UNTIL, TK_WHILE,
|
30
|
+
/* other terminal symbols */
|
31
|
+
TK_CONCAT, TK_DOTS, TK_EQ, TK_GE, TK_LE, TK_NE, TK_NUMBER,
|
32
|
+
TK_NAME, TK_STRING, TK_EOS
|
33
|
+
};
|
34
|
+
|
35
|
+
/* number of reserved words */
|
36
|
+
#define NUM_RESERVED (cast(int, TK_WHILE-FIRST_RESERVED+1))
|
37
|
+
|
38
|
+
|
39
|
+
/* array with token `names' */
|
40
|
+
LUAI_DATA const char *const luaX_tokens [];
|
41
|
+
|
42
|
+
|
43
|
+
typedef union {
|
44
|
+
lua_Number r;
|
45
|
+
TString *ts;
|
46
|
+
} SemInfo; /* semantics information */
|
47
|
+
|
48
|
+
|
49
|
+
typedef struct Token {
|
50
|
+
int token;
|
51
|
+
SemInfo seminfo;
|
52
|
+
} Token;
|
53
|
+
|
54
|
+
|
55
|
+
typedef struct LexState {
|
56
|
+
int current; /* current character (charint) */
|
57
|
+
int linenumber; /* input line counter */
|
58
|
+
int lastline; /* line of last token `consumed' */
|
59
|
+
Token t; /* current token */
|
60
|
+
Token lookahead; /* look ahead token */
|
61
|
+
struct FuncState *fs; /* `FuncState' is private to the parser */
|
62
|
+
struct lua_State *L;
|
63
|
+
ZIO *z; /* input stream */
|
64
|
+
Mbuffer *buff; /* buffer for tokens */
|
65
|
+
TString *source; /* current source name */
|
66
|
+
char decpoint; /* locale decimal point */
|
67
|
+
} LexState;
|
68
|
+
|
69
|
+
|
70
|
+
LUAI_FUNC void luaX_init (lua_State *L);
|
71
|
+
LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z,
|
72
|
+
TString *source);
|
73
|
+
LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l);
|
74
|
+
LUAI_FUNC void luaX_next (LexState *ls);
|
75
|
+
LUAI_FUNC void luaX_lookahead (LexState *ls);
|
76
|
+
LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token);
|
77
|
+
LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s);
|
78
|
+
LUAI_FUNC const char *luaX_token2str (LexState *ls, int token);
|
79
|
+
|
80
|
+
|
81
|
+
#endif
|
@@ -0,0 +1,128 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: llimits.h,v 1.69.1.1 2007/12/27 13:02:25 roberto Exp $
|
3
|
+
** Limits, basic types, and some other `installation-dependent' definitions
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef llimits_h
|
8
|
+
#define llimits_h
|
9
|
+
|
10
|
+
|
11
|
+
#include <limits.h>
|
12
|
+
#include <stddef.h>
|
13
|
+
|
14
|
+
|
15
|
+
#include "lua.h"
|
16
|
+
|
17
|
+
|
18
|
+
typedef LUAI_UINT32 lu_int32;
|
19
|
+
|
20
|
+
typedef LUAI_UMEM lu_mem;
|
21
|
+
|
22
|
+
typedef LUAI_MEM l_mem;
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
/* chars used as small naturals (so that `char' is reserved for characters) */
|
27
|
+
typedef unsigned char lu_byte;
|
28
|
+
|
29
|
+
|
30
|
+
#define MAX_SIZET ((size_t)(~(size_t)0)-2)
|
31
|
+
|
32
|
+
#define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
|
33
|
+
|
34
|
+
|
35
|
+
#define MAX_INT (INT_MAX-2) /* maximum value of an int (-2 for safety) */
|
36
|
+
|
37
|
+
/*
|
38
|
+
** conversion of pointer to integer
|
39
|
+
** this is for hashing only; there is no problem if the integer
|
40
|
+
** cannot hold the whole pointer value
|
41
|
+
*/
|
42
|
+
#define IntPoint(p) ((unsigned int)(lu_mem)(p))
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
/* type to ensure maximum alignment */
|
47
|
+
typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
|
48
|
+
|
49
|
+
|
50
|
+
/* result of a `usual argument conversion' over lua_Number */
|
51
|
+
typedef LUAI_UACNUMBER l_uacNumber;
|
52
|
+
|
53
|
+
|
54
|
+
/* internal assertions for in-house debugging */
|
55
|
+
#ifdef lua_assert
|
56
|
+
|
57
|
+
#define check_exp(c,e) (lua_assert(c), (e))
|
58
|
+
#define api_check(l,e) lua_assert(e)
|
59
|
+
|
60
|
+
#else
|
61
|
+
|
62
|
+
#define lua_assert(c) ((void)0)
|
63
|
+
#define check_exp(c,e) (e)
|
64
|
+
#define api_check luai_apicheck
|
65
|
+
|
66
|
+
#endif
|
67
|
+
|
68
|
+
|
69
|
+
#ifndef UNUSED
|
70
|
+
#define UNUSED(x) ((void)(x)) /* to avoid warnings */
|
71
|
+
#endif
|
72
|
+
|
73
|
+
|
74
|
+
#ifndef cast
|
75
|
+
#define cast(t, exp) ((t)(exp))
|
76
|
+
#endif
|
77
|
+
|
78
|
+
#define cast_byte(i) cast(lu_byte, (i))
|
79
|
+
#define cast_num(i) cast(lua_Number, (i))
|
80
|
+
#define cast_int(i) cast(int, (i))
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
/*
|
85
|
+
** type for virtual-machine instructions
|
86
|
+
** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
|
87
|
+
*/
|
88
|
+
typedef lu_int32 Instruction;
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
/* maximum stack for a Lua function */
|
93
|
+
#define MAXSTACK 250
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
/* minimum size for the string table (must be power of 2) */
|
98
|
+
#ifndef MINSTRTABSIZE
|
99
|
+
#define MINSTRTABSIZE 32
|
100
|
+
#endif
|
101
|
+
|
102
|
+
|
103
|
+
/* minimum size for string buffer */
|
104
|
+
#ifndef LUA_MINBUFFER
|
105
|
+
#define LUA_MINBUFFER 32
|
106
|
+
#endif
|
107
|
+
|
108
|
+
|
109
|
+
#ifndef lua_lock
|
110
|
+
#define lua_lock(L) ((void) 0)
|
111
|
+
#define lua_unlock(L) ((void) 0)
|
112
|
+
#endif
|
113
|
+
|
114
|
+
#ifndef luai_threadyield
|
115
|
+
#define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
|
116
|
+
#endif
|
117
|
+
|
118
|
+
|
119
|
+
/*
|
120
|
+
** macro to control inclusion of some hard tests on stack reallocation
|
121
|
+
*/
|
122
|
+
#ifndef HARDSTACKTESTS
|
123
|
+
#define condhardstacktests(x) ((void)0)
|
124
|
+
#else
|
125
|
+
#define condhardstacktests(x) x
|
126
|
+
#endif
|
127
|
+
|
128
|
+
#endif
|
@@ -0,0 +1,263 @@
|
|
1
|
+
/*
|
2
|
+
** $Id: lmathlib.c,v 1.67.1.1 2007/12/27 13:02:25 roberto Exp $
|
3
|
+
** Standard mathematical library
|
4
|
+
** See Copyright Notice in lua.h
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include <math.h>
|
10
|
+
|
11
|
+
#define lmathlib_c
|
12
|
+
#define LUA_LIB
|
13
|
+
|
14
|
+
#include "lua.h"
|
15
|
+
|
16
|
+
#include "lauxlib.h"
|
17
|
+
#include "lualib.h"
|
18
|
+
|
19
|
+
|
20
|
+
#undef PI
|
21
|
+
#define PI (3.14159265358979323846)
|
22
|
+
#define RADIANS_PER_DEGREE (PI/180.0)
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
static int math_abs (lua_State *L) {
|
27
|
+
lua_pushnumber(L, fabs(luaL_checknumber(L, 1)));
|
28
|
+
return 1;
|
29
|
+
}
|
30
|
+
|
31
|
+
static int math_sin (lua_State *L) {
|
32
|
+
lua_pushnumber(L, sin(luaL_checknumber(L, 1)));
|
33
|
+
return 1;
|
34
|
+
}
|
35
|
+
|
36
|
+
static int math_sinh (lua_State *L) {
|
37
|
+
lua_pushnumber(L, sinh(luaL_checknumber(L, 1)));
|
38
|
+
return 1;
|
39
|
+
}
|
40
|
+
|
41
|
+
static int math_cos (lua_State *L) {
|
42
|
+
lua_pushnumber(L, cos(luaL_checknumber(L, 1)));
|
43
|
+
return 1;
|
44
|
+
}
|
45
|
+
|
46
|
+
static int math_cosh (lua_State *L) {
|
47
|
+
lua_pushnumber(L, cosh(luaL_checknumber(L, 1)));
|
48
|
+
return 1;
|
49
|
+
}
|
50
|
+
|
51
|
+
static int math_tan (lua_State *L) {
|
52
|
+
lua_pushnumber(L, tan(luaL_checknumber(L, 1)));
|
53
|
+
return 1;
|
54
|
+
}
|
55
|
+
|
56
|
+
static int math_tanh (lua_State *L) {
|
57
|
+
lua_pushnumber(L, tanh(luaL_checknumber(L, 1)));
|
58
|
+
return 1;
|
59
|
+
}
|
60
|
+
|
61
|
+
static int math_asin (lua_State *L) {
|
62
|
+
lua_pushnumber(L, asin(luaL_checknumber(L, 1)));
|
63
|
+
return 1;
|
64
|
+
}
|
65
|
+
|
66
|
+
static int math_acos (lua_State *L) {
|
67
|
+
lua_pushnumber(L, acos(luaL_checknumber(L, 1)));
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
|
71
|
+
static int math_atan (lua_State *L) {
|
72
|
+
lua_pushnumber(L, atan(luaL_checknumber(L, 1)));
|
73
|
+
return 1;
|
74
|
+
}
|
75
|
+
|
76
|
+
static int math_atan2 (lua_State *L) {
|
77
|
+
lua_pushnumber(L, atan2(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
|
78
|
+
return 1;
|
79
|
+
}
|
80
|
+
|
81
|
+
static int math_ceil (lua_State *L) {
|
82
|
+
lua_pushnumber(L, ceil(luaL_checknumber(L, 1)));
|
83
|
+
return 1;
|
84
|
+
}
|
85
|
+
|
86
|
+
static int math_floor (lua_State *L) {
|
87
|
+
lua_pushnumber(L, floor(luaL_checknumber(L, 1)));
|
88
|
+
return 1;
|
89
|
+
}
|
90
|
+
|
91
|
+
static int math_fmod (lua_State *L) {
|
92
|
+
lua_pushnumber(L, fmod(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
|
93
|
+
return 1;
|
94
|
+
}
|
95
|
+
|
96
|
+
static int math_modf (lua_State *L) {
|
97
|
+
double ip;
|
98
|
+
double fp = modf(luaL_checknumber(L, 1), &ip);
|
99
|
+
lua_pushnumber(L, ip);
|
100
|
+
lua_pushnumber(L, fp);
|
101
|
+
return 2;
|
102
|
+
}
|
103
|
+
|
104
|
+
static int math_sqrt (lua_State *L) {
|
105
|
+
lua_pushnumber(L, sqrt(luaL_checknumber(L, 1)));
|
106
|
+
return 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
static int math_pow (lua_State *L) {
|
110
|
+
lua_pushnumber(L, pow(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
|
111
|
+
return 1;
|
112
|
+
}
|
113
|
+
|
114
|
+
static int math_log (lua_State *L) {
|
115
|
+
lua_pushnumber(L, log(luaL_checknumber(L, 1)));
|
116
|
+
return 1;
|
117
|
+
}
|
118
|
+
|
119
|
+
static int math_log10 (lua_State *L) {
|
120
|
+
lua_pushnumber(L, log10(luaL_checknumber(L, 1)));
|
121
|
+
return 1;
|
122
|
+
}
|
123
|
+
|
124
|
+
static int math_exp (lua_State *L) {
|
125
|
+
lua_pushnumber(L, exp(luaL_checknumber(L, 1)));
|
126
|
+
return 1;
|
127
|
+
}
|
128
|
+
|
129
|
+
static int math_deg (lua_State *L) {
|
130
|
+
lua_pushnumber(L, luaL_checknumber(L, 1)/RADIANS_PER_DEGREE);
|
131
|
+
return 1;
|
132
|
+
}
|
133
|
+
|
134
|
+
static int math_rad (lua_State *L) {
|
135
|
+
lua_pushnumber(L, luaL_checknumber(L, 1)*RADIANS_PER_DEGREE);
|
136
|
+
return 1;
|
137
|
+
}
|
138
|
+
|
139
|
+
static int math_frexp (lua_State *L) {
|
140
|
+
int e;
|
141
|
+
lua_pushnumber(L, frexp(luaL_checknumber(L, 1), &e));
|
142
|
+
lua_pushinteger(L, e);
|
143
|
+
return 2;
|
144
|
+
}
|
145
|
+
|
146
|
+
static int math_ldexp (lua_State *L) {
|
147
|
+
lua_pushnumber(L, ldexp(luaL_checknumber(L, 1), luaL_checkint(L, 2)));
|
148
|
+
return 1;
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
static int math_min (lua_State *L) {
|
154
|
+
int n = lua_gettop(L); /* number of arguments */
|
155
|
+
lua_Number dmin = luaL_checknumber(L, 1);
|
156
|
+
int i;
|
157
|
+
for (i=2; i<=n; i++) {
|
158
|
+
lua_Number d = luaL_checknumber(L, i);
|
159
|
+
if (d < dmin)
|
160
|
+
dmin = d;
|
161
|
+
}
|
162
|
+
lua_pushnumber(L, dmin);
|
163
|
+
return 1;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
static int math_max (lua_State *L) {
|
168
|
+
int n = lua_gettop(L); /* number of arguments */
|
169
|
+
lua_Number dmax = luaL_checknumber(L, 1);
|
170
|
+
int i;
|
171
|
+
for (i=2; i<=n; i++) {
|
172
|
+
lua_Number d = luaL_checknumber(L, i);
|
173
|
+
if (d > dmax)
|
174
|
+
dmax = d;
|
175
|
+
}
|
176
|
+
lua_pushnumber(L, dmax);
|
177
|
+
return 1;
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
static int math_random (lua_State *L) {
|
182
|
+
/* the `%' avoids the (rare) case of r==1, and is needed also because on
|
183
|
+
some systems (SunOS!) `rand()' may return a value larger than RAND_MAX */
|
184
|
+
lua_Number r = (lua_Number)(rand()%RAND_MAX) / (lua_Number)RAND_MAX;
|
185
|
+
switch (lua_gettop(L)) { /* check number of arguments */
|
186
|
+
case 0: { /* no arguments */
|
187
|
+
lua_pushnumber(L, r); /* Number between 0 and 1 */
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
case 1: { /* only upper limit */
|
191
|
+
int u = luaL_checkint(L, 1);
|
192
|
+
luaL_argcheck(L, 1<=u, 1, "interval is empty");
|
193
|
+
lua_pushnumber(L, floor(r*u)+1); /* int between 1 and `u' */
|
194
|
+
break;
|
195
|
+
}
|
196
|
+
case 2: { /* lower and upper limits */
|
197
|
+
int l = luaL_checkint(L, 1);
|
198
|
+
int u = luaL_checkint(L, 2);
|
199
|
+
luaL_argcheck(L, l<=u, 2, "interval is empty");
|
200
|
+
lua_pushnumber(L, floor(r*(u-l+1))+l); /* int between `l' and `u' */
|
201
|
+
break;
|
202
|
+
}
|
203
|
+
default: return luaL_error(L, "wrong number of arguments");
|
204
|
+
}
|
205
|
+
return 1;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
static int math_randomseed (lua_State *L) {
|
210
|
+
srand(luaL_checkint(L, 1));
|
211
|
+
return 0;
|
212
|
+
}
|
213
|
+
|
214
|
+
|
215
|
+
static const luaL_Reg mathlib[] = {
|
216
|
+
{"abs", math_abs},
|
217
|
+
{"acos", math_acos},
|
218
|
+
{"asin", math_asin},
|
219
|
+
{"atan2", math_atan2},
|
220
|
+
{"atan", math_atan},
|
221
|
+
{"ceil", math_ceil},
|
222
|
+
{"cosh", math_cosh},
|
223
|
+
{"cos", math_cos},
|
224
|
+
{"deg", math_deg},
|
225
|
+
{"exp", math_exp},
|
226
|
+
{"floor", math_floor},
|
227
|
+
{"fmod", math_fmod},
|
228
|
+
{"frexp", math_frexp},
|
229
|
+
{"ldexp", math_ldexp},
|
230
|
+
{"log10", math_log10},
|
231
|
+
{"log", math_log},
|
232
|
+
{"max", math_max},
|
233
|
+
{"min", math_min},
|
234
|
+
{"modf", math_modf},
|
235
|
+
{"pow", math_pow},
|
236
|
+
{"rad", math_rad},
|
237
|
+
{"random", math_random},
|
238
|
+
{"randomseed", math_randomseed},
|
239
|
+
{"sinh", math_sinh},
|
240
|
+
{"sin", math_sin},
|
241
|
+
{"sqrt", math_sqrt},
|
242
|
+
{"tanh", math_tanh},
|
243
|
+
{"tan", math_tan},
|
244
|
+
{NULL, NULL}
|
245
|
+
};
|
246
|
+
|
247
|
+
|
248
|
+
/*
|
249
|
+
** Open math library
|
250
|
+
*/
|
251
|
+
LUALIB_API int luaopen_math (lua_State *L) {
|
252
|
+
luaL_register(L, LUA_MATHLIBNAME, mathlib);
|
253
|
+
lua_pushnumber(L, PI);
|
254
|
+
lua_setfield(L, -2, "pi");
|
255
|
+
lua_pushnumber(L, HUGE_VAL);
|
256
|
+
lua_setfield(L, -2, "huge");
|
257
|
+
#if defined(LUA_COMPAT_MOD)
|
258
|
+
lua_getfield(L, -1, "fmod");
|
259
|
+
lua_setfield(L, -2, "mod");
|
260
|
+
#endif
|
261
|
+
return 1;
|
262
|
+
}
|
263
|
+
|