From 58a49b7ffb315930ec8f7f10d0b5846bd710689f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergiusz=20Baza=C5=84ski?= Date: Thu, 23 Aug 2012 15:44:36 +0200 Subject: [PATCH] Including stubs for Lua to use. Because I forgot them. --- Kernel/include/Lua/errno.h | 1 + Kernel/include/Lua/stdio.h | 29 +++++++++++++++++++++- Kernel/include/Lua/stdlib.h | 6 +++++ Kernel/include/Lua/string.h | 30 +++++------------------ Kernel/src/Lua/Makefile | 7 +++--- Kernel/src/Lua/glue.c | 10 ++++++++ Kernel/src/Lua/lua.c | 49 +++++++++++++++++++------------------ 7 files changed, 80 insertions(+), 52 deletions(-) diff --git a/Kernel/include/Lua/errno.h b/Kernel/include/Lua/errno.h index afa44e8..c4aeb54 100644 --- a/Kernel/include/Lua/errno.h +++ b/Kernel/include/Lua/errno.h @@ -2,5 +2,6 @@ #define __TIER0_ANSI_ERRNO_H__ #define E2BIG 7 +extern int errno; #endif diff --git a/Kernel/include/Lua/stdio.h b/Kernel/include/Lua/stdio.h index 8faae64..7ac83d0 100644 --- a/Kernel/include/Lua/stdio.h +++ b/Kernel/include/Lua/stdio.h @@ -2,11 +2,38 @@ #define __TIER0_ANSI_STDIO_H__ #include -#include "Tier0/kstdlib.h" //int printf(char *format, va_list args); #define BUFSIZ 1024 #define FILE int int sprintf(char *str, const char *format, ...); +int feof(FILE *stream); +unsigned int fread(void *ptr, unsigned long long int size, unsigned long long int count, FILE *stream); +int getc(FILE *stream); +char *fgets(char *s, int size, FILE *stream); +FILE *fopen(const char *path, const char *mode); +FILE *freopen(const char *path, const char *mode, FILE *stream); +int ferror(FILE *stream); +int fclose(FILE *stream); +int fprintf(FILE *stream, const char *format, ...); +int fflush(FILE *stream); +FILE *tmpfile(void); +int fscanf(FILE *stream, const char *format, ...); +int ungetc(int c, FILE *stream); +int clearerr(FILE *stream); +unsigned long long int fwrite(const void *ptr, unsigned long long int size, unsigned long long int nmemb, FILE *stream); +int fseek(FILE *stream, long offset, int whence); +int ftell(FILE *stream); +int fputs(const char *s, FILE *stream); +int printf(const char *format, ...); + +#define EOF -1 +extern FILE *stdin; +extern FILE *stdout; +extern FILE *stderr; + +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 #endif diff --git a/Kernel/include/Lua/stdlib.h b/Kernel/include/Lua/stdlib.h index 14916ac..3479c82 100644 --- a/Kernel/include/Lua/stdlib.h +++ b/Kernel/include/Lua/stdlib.h @@ -2,8 +2,14 @@ #define __TIER0_ANSI_STDLIB_H__ void *malloc(unsigned long long int size); +void free(void *); +void *realloc(void *ptr, unsigned long long int size); int abs(int X); void abort(void); long int strtol(const char *nptr, char **endptr, int base); +void exit(int status); + +#define EXIT_SUCCESS 0 +#define EXIT_FAILURE 1 #endif diff --git a/Kernel/include/Lua/string.h b/Kernel/include/Lua/string.h index 96f8b2d..1f2b491 100644 --- a/Kernel/include/Lua/string.h +++ b/Kernel/include/Lua/string.h @@ -7,31 +7,13 @@ const char *strchr (const char *str, int character); inline int strcmp(const char *s1, const char *s2); char *strpbrk(const char *s1, const char *s2); +char *strerror(int errnum); +char *strstr(const char *haystack, const char *needle); +unsigned long long int strspn(const char *s, const char *accept); +void *memchr(const void *s, int c, unsigned long long int n); +char *strcpy(char *dest, const char *src); -const char *strchr (const char *str, int character) -{ - while (*str != 0) - { - if (*str == character) - return str; - str++; - } - return 0; -} -inline int strcmp(const char *s1, const char *s2) -{ - while((*s1 && *s2) && (*s1++ == *s2++)); - return *(--s1) - *(--s2); -} - -char *strpbrk(const char *s1, const char *s2) -{ - while(*s1) - if(strchr(s2, *s1++)) - return (char*)--s1; - return 0; -} - +#define strcoll(A, B) strcmp(A, B) #define strlen(A) kstrlen(A) #define memcpy(A, B, C) kmemcpy(A, B, C) #define memcmp(A, B, C) kmemcmp((const u8*)A, (const u8*)B, C) diff --git a/Kernel/src/Lua/Makefile b/Kernel/src/Lua/Makefile index d005613..a3f7b74 100644 --- a/Kernel/src/Lua/Makefile +++ b/Kernel/src/Lua/Makefile @@ -32,8 +32,9 @@ LUA_A= liblua.a CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o \ lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o \ ltm.o lundump.o lvm.o lzio.o snprintf.o glue.o -LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o \ - lmathlib.o loslib.o lstrlib.o ltablib.o loadlib.o linit.o +# removed mathlib, oslib, iolib, loadlib ~q3k +LIB_O= lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o \ + lstrlib.o ltablib.o linit.o BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS) LUA_T= lua @@ -98,7 +99,7 @@ bsd: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E" cucumber-kernel: - $(MAKE) $(ALL) SYSCFLAGS="-DLUA_ANSI -I\"../../include/Lua/\" -I\"../../include/\"" + $(MAKE) $(ALL_O) SYSCFLAGS="-DLUA_ANSI -I\"../../include/Lua/\" -I\"../../include/\"" freebsd: $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -lreadline" diff --git a/Kernel/src/Lua/glue.c b/Kernel/src/Lua/glue.c index 5bb5614..4c65d9d 100644 --- a/Kernel/src/Lua/glue.c +++ b/Kernel/src/Lua/glue.c @@ -3,11 +3,20 @@ #include #include "setjmp.h" +#include "stdio.h" #include "Tier0/panic.h" #include "Tier0/kstdio.h" int errno; +// file descriptors for stdio... +FILE _stdin = 0; +FILE _stdout = 1; +FILE _stderr = 2; +FILE *stdin = &_stdin; +FILE *stdout = &_stderr; +FILE *stderr = &_stderr; + // math.h implementation //double floor(double X) //{ @@ -66,6 +75,7 @@ int abs(int X) void abort(void) { PANIC("abort() stub."); + __builtin_unreachable(); } // string.h implementation diff --git a/Kernel/src/Lua/lua.c b/Kernel/src/Lua/lua.c index 7614c70..294476e 100644 --- a/Kernel/src/Lua/lua.c +++ b/Kernel/src/Lua/lua.c @@ -5,7 +5,7 @@ */ -#include +//#include #include #include #include @@ -91,18 +91,18 @@ static const char *progname = LUA_PROGNAME; -static void lstop (lua_State *L, lua_Debug *ar) { - (void)ar; /* unused arg. */ - lua_sethook(L, NULL, 0, 0); - luaL_error(L, "interrupted!"); -} +//static void lstop (lua_State *L, lua_Debug *ar) { +// (void)ar; /* unused arg. */ +// lua_sethook(L, NULL, 0, 0); +// luaL_error(L, "interrupted!"); +//} -static void laction (int i) { - signal(i, SIG_DFL); /* if another SIGINT happens before lstop, - terminate process (default action) */ - lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); -} +//static void laction (int i) { +// signal(i, SIG_DFL); /* if another SIGINT happens before lstop, +// terminate process (default action) */ +// lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); +//} static void print_usage (const char *badoption) { @@ -175,9 +175,9 @@ static int docall (lua_State *L, int narg, int nres) { lua_pushcfunction(L, traceback); /* push traceback function */ lua_insert(L, base); /* put it under chunk and args */ globalL = L; /* to be available to 'laction' */ - signal(SIGINT, laction); + //signal(SIGINT, laction); status = lua_pcall(L, narg, nres, base); - signal(SIGINT, SIG_DFL); + //signal(SIGINT, SIG_DFL); lua_remove(L, base); /* remove traceback function */ return status; } @@ -420,17 +420,18 @@ static int runargs (lua_State *L, char **argv, int n) { static int handle_luainit (lua_State *L) { - const char *name = "=" LUA_INITVERSION; - const char *init = getenv(name + 1); - if (init == NULL) { - name = "=" LUA_INIT; - init = getenv(name + 1); /* try alternative name */ - } - if (init == NULL) return LUA_OK; - else if (init[0] == '@') - return dofile(L, init+1); - else - return dostring(L, init, name); + //const char *name = "=" LUA_INITVERSION; + //const char *init = getenv(name + 1); + //if (init == NULL) { + // name = "=" LUA_INIT; + // init = getenv(name + 1); /* try alternative name */ + //} + //if (init == NULL) return LUA_OK; + //else if (init[0] == '@') + // return dofile(L, init+1); + //else + // return dostring(L, init, name); + return LUA_OK; }