summaryrefslogtreecommitdiff
path: root/src/luac/stubs.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2000-11-06 12:00:00 +0000
committerrepogen <>2000-11-06 12:00:00 +0000
commit8cb71cb5548e3138e5d4e4744f52c79d9fafb116 (patch)
tree25859eb162c67eafc46866e0ec3a9a7ebf93157a /src/luac/stubs.c
parentb7610da5fed99f59ac73ae452da8839a0f2c1bda (diff)
downloadlua-github-4.0.tar.gz
Lua 4.04.0
Diffstat (limited to 'src/luac/stubs.c')
-rw-r--r--src/luac/stubs.c176
1 files changed, 91 insertions, 85 deletions
diff --git a/src/luac/stubs.c b/src/luac/stubs.c
index 5f38940e..74f509eb 100644
--- a/src/luac/stubs.c
+++ b/src/luac/stubs.c
@@ -1,68 +1,109 @@
/*
-** $Id: stubs.c,v 1.11 1999/03/11 17:09:10 lhf Exp $
+** $Id: stubs.c,v 1.20 2000/10/31 16:57:23 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 "ldo.h"
+#include "llex.h"
#include "luac.h"
+#undef L
+
+#ifndef NOSTUBS
+
+const char luac_ident[] = "$luac: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
+ "$Authors: " LUA_AUTHORS " $";
/*
-* avoid lapi lauxlib lbuiltin ldo lgc ltable ltm lvm
-* use only lbuffer lfunc llex lmem lobject lparser lstate lstring lzio
+* avoid lapi ldebug ldo lgc lstate ltm lvm
+* use only lcode lfunc llex lmem lobject lparser lstring ltable lzio
*/
/* simplified from ldo.c */
-void lua_error(char* s)
-{
- if (s) fprintf(stderr,"luac: %s\n",s);
- exit(1);
+void lua_error (lua_State* L, const char* s) {
+ UNUSED(L);
+ 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);
+/* simplified from ldo.c */
+void luaD_breakrun (lua_State *L, int errcode) {
+ UNUSED(errcode);
+ lua_error(L,"memory allocation error");
}
-/* 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' */
+/* simplified from lstate.c */
+lua_State *lua_open (int stacksize) {
+ lua_State *L = luaM_new(NULL, lua_State);
+ if (L == NULL) return NULL; /* memory allocation error */
+ L->stack = NULL;
+ L->strt.size = L->udt.size = 0;
+ L->strt.nuse = L->udt.nuse = 0;
+ L->strt.hash = NULL;
+ L->udt.hash = NULL;
+ L->Mbuffer = NULL;
+ L->Mbuffsize = 0;
+ L->rootproto = NULL;
+ L->rootcl = NULL;
+ L->roottable = NULL;
+ L->TMtable = NULL;
+ L->last_tag = -1;
+ L->refArray = NULL;
+ L->refSize = 0;
+ L->refFree = NONEXT;
+ L->nblocks = sizeof(lua_State);
+ L->GCthreshold = MAX_INT; /* to avoid GC during pre-definitions */
+ L->callhook = NULL;
+ L->linehook = NULL;
+ L->allowhooks = 1;
+ L->errorJmp = NULL;
+ if (stacksize == 0)
+ stacksize = DEFAULT_STACK_SIZE;
+ else
+ stacksize += LUA_MINSTACK;
+ L->gt = luaH_new(L, 10); /* table of globals */
+ luaS_init(L);
+ luaX_init(L);
+ L->GCthreshold = 2*L->nblocks;
+ return L;
}
-/* 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){}
+/* copied from ldebug.c */
+int luaG_getline (int *lineinfo, int pc, int refline, int *prefi) {
+ int refi;
+ if (lineinfo == NULL || pc == -1)
+ return -1; /* no line info or function is not active */
+ refi = prefi ? *prefi : 0;
+ if (lineinfo[refi] < 0)
+ refline += -lineinfo[refi++];
+ LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info");
+ while (lineinfo[refi] > pc) {
+ refline--;
+ refi--;
+ if (lineinfo[refi] < 0)
+ refline -= -lineinfo[refi--];
+ LUA_ASSERT(lineinfo[refi] >= 0, "invalid line info");
+ }
+ for (;;) {
+ int nextline = refline + 1;
+ int nextref = refi + 1;
+ if (lineinfo[nextref] < 0)
+ nextline += -lineinfo[nextref++];
+ LUA_ASSERT(lineinfo[nextref] >= 0, "invalid line info");
+ if (lineinfo[nextref] > pc)
+ break;
+ refline = nextline;
+ refi = nextref;
+ }
+ if (prefi) *prefi = refi;
+ return refline;
+}
/*
-* the code below avoids the lexer and the parser (llex lparser).
+* the code below avoids the lexer and the parser (llex lparser lcode).
* it is useful if you only want to load binary files.
* this works for interpreters like lua.c too.
*/
@@ -72,49 +113,14 @@ void luaT_init(void){}
#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 luaX_init(lua_State *L) {
+ UNUSED(L);
}
-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);
+Proto *luaY_parser(lua_State *L, ZIO *z) {
+ UNUSED(z);
+ lua_error(L,"parser not loaded");
+ return NULL;
}
#endif