diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-18 12:30:50 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-03-18 12:30:50 -0300 |
| commit | 2de803c250de373186afbbea0a5978f54c52850c (patch) | |
| tree | a00499eac71bb427fd720e45bdfa2749dd134b51 | |
| parent | fa08b42dd851ae945df9796438ac0565939a00f2 (diff) | |
| download | lua-2de803c250de373186afbbea0a5978f54c52850c.tar.gz lua-2de803c250de373186afbbea0a5978f54c52850c.tar.bz2 lua-2de803c250de373186afbbea0a5978f54c52850c.zip | |
new header 'auxlib.h' + new function luaL_verror
| -rw-r--r-- | auxlib.c | 27 | ||||
| -rw-r--r-- | iolib.c | 12 | ||||
| -rw-r--r-- | lex.c | 7 | ||||
| -rw-r--r-- | lualib.h | 9 | ||||
| -rw-r--r-- | mathlib.c | 7 | ||||
| -rw-r--r-- | strlib.c | 15 |
6 files changed, 41 insertions, 36 deletions
| @@ -1,20 +1,20 @@ | |||
| 1 | char *rcs_auxlib="$Id: $"; | 1 | char *rcs_auxlib="$Id: auxlib.c,v 1.1 1997/03/17 17:02:29 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | #include <stdio.h> | 3 | #include <stdio.h> |
| 4 | #include <stdarg.h> | ||
| 4 | 5 | ||
| 5 | #include "lua.h" | 6 | #include "lua.h" |
| 7 | #include "auxlib.h" | ||
| 6 | 8 | ||
| 7 | 9 | ||
| 8 | void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg) | 10 | void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg) |
| 9 | { | 11 | { |
| 10 | if (!cond) { | 12 | if (!cond) { |
| 11 | char buff[100]; | ||
| 12 | if (extramsg == NULL) | 13 | if (extramsg == NULL) |
| 13 | sprintf(buff, "bad argument #%d to function `%s'", numarg, funcname); | 14 | luaL_verror("bad argument #%d to function `%s'", numarg, funcname); |
| 14 | else | 15 | else |
| 15 | sprintf(buff, "bad argument #%d to function `%s' (%s)", | 16 | luaL_verror("bad argument #%d to function `%s' (%s)", |
| 16 | numarg, funcname, extramsg); | 17 | numarg, funcname, extramsg); |
| 17 | lua_error(buff); | ||
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | 20 | ||
| @@ -45,3 +45,20 @@ double luaL_opt_number (int numArg, double def, char *funcname) | |||
| 45 | luaL_check_number(numArg, funcname); | 45 | luaL_check_number(numArg, funcname); |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | void luaL_openlib (struct luaL_reg *l, int n) | ||
| 49 | { | ||
| 50 | int i; | ||
| 51 | for (i=0; i<n; i++) | ||
| 52 | lua_register(l[i].name, l[i].func); | ||
| 53 | } | ||
| 54 | |||
| 55 | |||
| 56 | void luaL_verror (char *fmt, ...) | ||
| 57 | { | ||
| 58 | char buff[1000]; | ||
| 59 | va_list argp; | ||
| 60 | va_start(argp, fmt); | ||
| 61 | vsprintf(buff, fmt, argp); | ||
| 62 | va_end(argp); | ||
| 63 | lua_error(buff); | ||
| 64 | } | ||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <errno.h> | 5 | #include <errno.h> |
| 6 | 6 | ||
| 7 | #include "lua.h" | 7 | #include "lua.h" |
| 8 | #include "auxlib.h" | ||
| 8 | #include "luadebug.h" | 9 | #include "luadebug.h" |
| 9 | #include "lualib.h" | 10 | #include "lualib.h" |
| 10 | 11 | ||
| @@ -234,13 +235,12 @@ static void io_debug (void) | |||
| 234 | 235 | ||
| 235 | static void lua_printstack (FILE *f) | 236 | static void lua_printstack (FILE *f) |
| 236 | { | 237 | { |
| 237 | int level = 0; | 238 | int level = 1; /* skip level 0 (it's this function) */ |
| 238 | lua_Object func; | 239 | lua_Object func; |
| 239 | fprintf(f, "Active Stack:\n"); | ||
| 240 | while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { | 240 | while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) { |
| 241 | char *name; | 241 | char *name; |
| 242 | int currentline; | 242 | int currentline; |
| 243 | fprintf(f, "\t"); | 243 | fprintf(f, (level==2) ? "Active Stack:\n\t" : "\t"); |
| 244 | switch (*lua_getobjname(func, &name)) { | 244 | switch (*lua_getobjname(func, &name)) { |
| 245 | case 'g': | 245 | case 'g': |
| 246 | fprintf(f, "function %s", name); | 246 | fprintf(f, "function %s", name); |
| @@ -275,7 +275,7 @@ static void errorfb (void) | |||
| 275 | } | 275 | } |
| 276 | 276 | ||
| 277 | 277 | ||
| 278 | static struct lua_reg iolib[] = { | 278 | static struct luaL_reg iolib[] = { |
| 279 | {"readfrom", io_readfrom}, | 279 | {"readfrom", io_readfrom}, |
| 280 | {"writeto", io_writeto}, | 280 | {"writeto", io_writeto}, |
| 281 | {"appendto", io_appendto}, | 281 | {"appendto", io_appendto}, |
| @@ -295,6 +295,6 @@ static struct lua_reg iolib[] = { | |||
| 295 | void iolib_open (void) | 295 | void iolib_open (void) |
| 296 | { | 296 | { |
| 297 | lua_infile=stdin; lua_outfile=stdout; | 297 | lua_infile=stdin; lua_outfile=stdout; |
| 298 | luaI_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); | 298 | luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); |
| 299 | lua_setfallback("error", errorfb); | 299 | lua_setglobalmethod("error", errorfb); |
| 300 | } | 300 | } |
| @@ -1,9 +1,10 @@ | |||
| 1 | char *rcs_lex = "$Id: lex.c,v 2.41 1996/11/22 13:08:02 roberto Exp roberto $"; | 1 | char *rcs_lex = "$Id: lex.c,v 2.42 1997/02/07 13:49:46 roberto Exp roberto $"; |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | #include <ctype.h> | 4 | #include <ctype.h> |
| 5 | #include <string.h> | 5 | #include <string.h> |
| 6 | 6 | ||
| 7 | #include "auxlib.h" | ||
| 7 | #include "mem.h" | 8 | #include "mem.h" |
| 8 | #include "tree.h" | 9 | #include "tree.h" |
| 9 | #include "table.h" | 10 | #include "table.h" |
| @@ -32,10 +33,8 @@ void lua_setinput (Input fn) | |||
| 32 | 33 | ||
| 33 | static void luaI_auxsyntaxerror (char *s, char *token) | 34 | static void luaI_auxsyntaxerror (char *s, char *token) |
| 34 | { | 35 | { |
| 35 | char msg[256]; | 36 | luaL_verror("%s;\n> last token read: \"%s\" at line %d in file %s", |
| 36 | sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s", | ||
| 37 | s, token, lua_linenumber, lua_parsedfile); | 37 | s, token, lua_linenumber, lua_parsedfile); |
| 38 | lua_error (msg); | ||
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | void luaI_syntaxerror (char *s) | 40 | void luaI_syntaxerror (char *s) |
| @@ -2,7 +2,7 @@ | |||
| 2 | ** Libraries to be used in LUA programs | 2 | ** Libraries to be used in LUA programs |
| 3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
| 4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
| 5 | ** $Id: lualib.h,v 1.10 1996/08/05 20:55:24 roberto Exp roberto $ | 5 | ** $Id: lualib.h,v 1.11 1997/03/17 17:01:10 roberto Exp roberto $ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef lualib_h | 8 | #ifndef lualib_h |
| @@ -15,14 +15,9 @@ void strlib_open (void); | |||
| 15 | void mathlib_open (void); | 15 | void mathlib_open (void); |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | /* auxiliar functions (private) */ | ||
| 19 | 18 | ||
| 20 | struct lua_reg { | 19 | /* auxiliar functions (private) */ |
| 21 | char *name; | ||
| 22 | lua_CFunction func; | ||
| 23 | }; | ||
| 24 | 20 | ||
| 25 | void luaI_openlib (struct lua_reg *l, int n); | ||
| 26 | char *luaI_addchar (int c); | 21 | char *luaI_addchar (int c); |
| 27 | void luaI_addquoted (char *s); | 22 | void luaI_addquoted (char *s); |
| 28 | 23 | ||
| @@ -3,12 +3,13 @@ | |||
| 3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.18 1996/08/01 14:55:33 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.19 1997/03/17 17:01:10 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| 10 | 10 | ||
| 11 | #include "lualib.h" | 11 | #include "lualib.h" |
| 12 | #include "auxlib.h" | ||
| 12 | #include "lua.h" | 13 | #include "lua.h" |
| 13 | 14 | ||
| 14 | #ifndef PI | 15 | #ifndef PI |
| @@ -195,7 +196,7 @@ static void math_randomseed (void) | |||
| 195 | } | 196 | } |
| 196 | 197 | ||
| 197 | 198 | ||
| 198 | static struct lua_reg mathlib[] = { | 199 | static struct luaL_reg mathlib[] = { |
| 199 | {"abs", math_abs}, | 200 | {"abs", math_abs}, |
| 200 | {"sin", math_sin}, | 201 | {"sin", math_sin}, |
| 201 | {"cos", math_cos}, | 202 | {"cos", math_cos}, |
| @@ -224,7 +225,7 @@ static struct lua_reg mathlib[] = { | |||
| 224 | */ | 225 | */ |
| 225 | void mathlib_open (void) | 226 | void mathlib_open (void) |
| 226 | { | 227 | { |
| 227 | luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); | 228 | luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); |
| 228 | old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); | 229 | old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); |
| 229 | } | 230 | } |
| 230 | 231 | ||
| @@ -3,7 +3,7 @@ | |||
| 3 | ** String library to LUA | 3 | ** String library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_strlib="$Id: strlib.c,v 1.35 1997/02/21 15:21:34 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.36 1997/03/17 17:01:10 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -11,6 +11,7 @@ char *rcs_strlib="$Id: strlib.c,v 1.35 1997/02/21 15:21:34 roberto Exp roberto $ | |||
| 11 | #include <ctype.h> | 11 | #include <ctype.h> |
| 12 | 12 | ||
| 13 | #include "lua.h" | 13 | #include "lua.h" |
| 14 | #include "auxlib.h" | ||
| 14 | #include "lualib.h" | 15 | #include "lualib.h" |
| 15 | 16 | ||
| 16 | 17 | ||
| @@ -518,15 +519,7 @@ static void str_format (void) | |||
| 518 | } | 519 | } |
| 519 | 520 | ||
| 520 | 521 | ||
| 521 | void luaI_openlib (struct lua_reg *l, int n) | 522 | static struct luaL_reg strlib[] = { |
| 522 | { | ||
| 523 | int i; | ||
| 524 | for (i=0; i<n; i++) | ||
| 525 | lua_register(l[i].name, l[i].func); | ||
| 526 | } | ||
| 527 | |||
| 528 | |||
| 529 | static struct lua_reg strlib[] = { | ||
| 530 | {"strtok", str_tok}, | 523 | {"strtok", str_tok}, |
| 531 | {"strlen", str_len}, | 524 | {"strlen", str_len}, |
| 532 | {"strsub", str_sub}, | 525 | {"strsub", str_sub}, |
| @@ -546,5 +539,5 @@ static struct lua_reg strlib[] = { | |||
| 546 | */ | 539 | */ |
| 547 | void strlib_open (void) | 540 | void strlib_open (void) |
| 548 | { | 541 | { |
| 549 | luaI_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0]))); | 542 | luaL_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0]))); |
| 550 | } | 543 | } |
