-
Notifications
You must be signed in to change notification settings - Fork 5
/
luaarduino.c
184 lines (145 loc) · 3.64 KB
/
luaarduino.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
Copyright (C) 2016 John M. Harris, Jr. <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This file is the result of my extreme laziness. Be warned, it's not
clean, but it works.
*/
//Default is to build the entire interpreter, we don't want that.
#ifndef MAKE_LIB
#ifndef MAKE_LUAC
#ifndef MAKE_LUA
#define MAKE_LUA
#endif
#endif
#endif
//Platform-specific features we're opting out of.
#if 0
#define LUA_USE_LINUX
#define LUA_USE_MACOSX
#define LUA_USE_POSIX
#define LUA_ANSI
#endif
#define HUGE_VAL (__builtin_huge_val())
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define BUFSIZ 256
size_t strxfrm(char* dest, const char* src, size_t n){
/* This implementation does not know about any locale but "C"... */
size_t n2 = strlen(src);
if(n > n2){
strcpy(dest,src);
}
return n2;
}
int strcoll(const char* s1, const char* s2){
char t1[1 + strxfrm(0, s1, 0)];
strxfrm(t1, s1, sizeof(t1));
char t2[1 + strxfrm(0, s2, 0)];
strxfrm(t2, s2, sizeof(t2));
return strcmp(t1, t2);
}
FILE* fopen(const char* path, const char* mode){
(void)path;
(void)mode;
return NULL;
}
FILE* freopen(const char* filename, const char* mode, FILE* stream){
return NULL;
}
char* strerror(int errnum){
return "Uknown error";
}
static int _lastSeedNumber = 38;//Magic number, how do you like me now?
//Modulus for prng
#define M 0x7FFFFFFF
unsigned long int prng(){//random number generator; call with 1 <= x <=M-1
unsigned long int x = _lastSeedNumber++;
if(x <= M-1){
_lastSeedNumber = 26;//More magic numbers!
}
x = (x >> 16) + ((x << 15) & M) - (x >> 21) - ((x << 10) & M);
if(x < 0){
x += M;
}
return x;
}
#define luai_makeseed prng
#define l_randomizePivot prng
#define LUA_C89_NUMBERS
#define LUA_USE_C89
#include "lua/luaconf.h"
#undef LUA_API
#define LUA_API
#undef LUALIB_API
#define LUALIB_API
#undef LUAMOD_API
#define LUAMOD_API
#undef LUAI_FUNC
#define LUAI_FUNC
#undef LUAI_DDEC
#define LUAI_DDEC
#if defined(lua_getlocaledecpoint)
#undef lua_getlocaledecpoint
#define lua_getlocaledecpoint() '.'
#endif
#define l_signalT int
#include "lua/lapi.c"
#include "lua/lcode.c"
#include "lua/lctype.c"
#include "lua/ldebug.c"
#include "lua/ldo.c"
#include "lua/ldump.c"
#include "lua/lfunc.c"
#include "lua/lgc.c"
#include "lua/llex.c"
#include "lua/lmem.c"
#include "lua/lobject.c"
#include "lua/lopcodes.c"
#include "lua/lparser.c"
#include "lua/lstate.c"
#include "lua/lstring.c"
#include "lua/ltable.c"
#include "lua/ltm.c"
#include "lua/lundump.c"
#define pushclosure pushclosure2
#include "lua/lvm.c"
#include "lua/lzio.c"
//Auxilary lib
#include "lua/lauxlib.c"
//Standard lib, not useeded for luac
#ifndef MAKE_LUAC
#include "lua/lbaselib.c"
//#include "lbitlib.c"
//#include "lcorolib.c"
#include "lua/ldblib.c"
//#include "liolib.c"
#include "lua/lmathlib.c"
//#include "loadlib.c"
//#include "loslib.c"
#include "lua/lstrlib.c"
#include "lua/ltablib.c"
#include "lua/lutf8lib.c"
//#include "linit.c"
#endif
//lua
#ifdef MAKE_LUA
//#include "lua.c"
#endif
//luac
#ifdef MAKE_LUAC
#include "luac.c"
#endif
#include "main.c"