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
|
/*
** $Id: stubs.c,v 1.11 1999/03/11 17:09:10 lhf Exp $
** avoid runtime modules in luac
** See Copyright Notice in lua.h
*/
#ifdef NOSTUBS
/* according to gcc, ANSI C forbids an empty source file */
void luaU_dummy(void);
void luaU_dummy(void){}
#else
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "luac.h"
/*
* avoid lapi lauxlib lbuiltin ldo lgc ltable ltm lvm
* use only lbuffer lfunc llex lmem lobject lparser lstate lstring lzio
*/
/* simplified from ldo.c */
void lua_error(char* s)
{
if (s) fprintf(stderr,"luac: %s\n",s);
exit(1);
}
/* copied from lauxlib.c */
void luaL_verror (char *fmt, ...)
{
char buff[500];
va_list argp;
va_start(argp, fmt);
vsprintf(buff, fmt, argp);
va_end(argp);
lua_error(buff);
}
/* copied from lauxlib.c */
void luaL_filesource (char *out, char *filename, int len) {
if (filename == NULL) filename = "(stdin)";
sprintf(out, "@%.*s", len-2, filename); /* -2 for '@' and '\0' */
}
/* avoid runtime modules in lstate.c */
#include "lbuiltin.h"
#include "ldo.h"
#include "lgc.h"
#include "ltable.h"
#include "ltm.h"
void luaB_predefine(void){}
void luaC_hashcallIM(Hash *l){}
void luaC_strcallIM(TaggedString *l){}
void luaD_gcIM(TObject *o){}
void luaH_free(Hash *frees){}
void luaT_init(void){}
/*
* the code below avoids the lexer and the parser (llex lparser).
* it is useful if you only want to load binary files.
* this works for interpreters like lua.c too.
*/
#ifdef NOPARSER
#include "llex.h"
#include "lparser.h"
void luaX_init(void){}
void luaD_init(void){}
TProtoFunc* luaY_parser(ZIO *z) {
lua_error("parser not loaded");
return NULL;
}
#else
/* copied from lauxlib.c */
int luaL_findstring (char *name, char *list[]) {
int i;
for (i=0; list[i]; i++)
if (strcmp(list[i], name) == 0)
return i;
return -1; /* name not found */
}
/* copied from lauxlib.c */
void luaL_chunkid (char *out, char *source, int len) {
len -= 13; /* 13 = strlen("string ''...\0") */
if (*source == '@')
sprintf(out, "file `%.*s'", len, source+1);
else if (*source == '(')
strcpy(out, "(C code)");
else {
char *b = strchr(source , '\n'); /* stop string at first new line */
int lim = (b && (b-source)<len) ? b-source : len;
sprintf(out, "string `%.*s'", lim, source);
strcpy(out+lim+(13-5), "...'"); /* 5 = strlen("...'\0") */
}
}
void luaD_checkstack(int n){}
#define STACK_UNIT 128
/* copied from ldo.c */
void luaD_init (void) {
L->stack.stack = luaM_newvector(STACK_UNIT, TObject);
L->stack.top = L->stack.stack;
L->stack.last = L->stack.stack+(STACK_UNIT-1);
}
#endif
#endif
|