aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--auxlib.c27
-rw-r--r--iolib.c12
-rw-r--r--lex.c7
-rw-r--r--lualib.h9
-rw-r--r--mathlib.c7
-rw-r--r--strlib.c15
6 files changed, 41 insertions, 36 deletions
diff --git a/auxlib.c b/auxlib.c
index 0bee6430..ea3b7678 100644
--- a/auxlib.c
+++ b/auxlib.c
@@ -1,20 +1,20 @@
1char *rcs_auxlib="$Id: $"; 1char *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
8void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg) 10void 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
48void 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
56void 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}
diff --git a/iolib.c b/iolib.c
index 8315707f..3dfedb28 100644
--- a/iolib.c
+++ b/iolib.c
@@ -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
235static void lua_printstack (FILE *f) 236static 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
278static struct lua_reg iolib[] = { 278static 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[] = {
295void iolib_open (void) 295void 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}
diff --git a/lex.c b/lex.c
index aa8bd588..76c48040 100644
--- a/lex.c
+++ b/lex.c
@@ -1,9 +1,10 @@
1char *rcs_lex = "$Id: lex.c,v 2.41 1996/11/22 13:08:02 roberto Exp roberto $"; 1char *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
33static void luaI_auxsyntaxerror (char *s, char *token) 34static 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
41void luaI_syntaxerror (char *s) 40void luaI_syntaxerror (char *s)
diff --git a/lualib.h b/lualib.h
index 6deb9e97..09af12fb 100644
--- a/lualib.h
+++ b/lualib.h
@@ -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);
15void mathlib_open (void); 15void mathlib_open (void);
16 16
17 17
18/* auxiliar functions (private) */
19 18
20struct lua_reg { 19/* auxiliar functions (private) */
21 char *name;
22 lua_CFunction func;
23};
24 20
25void luaI_openlib (struct lua_reg *l, int n);
26char *luaI_addchar (int c); 21char *luaI_addchar (int c);
27void luaI_addquoted (char *s); 22void luaI_addquoted (char *s);
28 23
diff --git a/mathlib.c b/mathlib.c
index 0ed1a9a6..798ba322 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,12 +3,13 @@
3** Mathematics library to LUA 3** Mathematics library to LUA
4*/ 4*/
5 5
6char *rcs_mathlib="$Id: mathlib.c,v 1.18 1996/08/01 14:55:33 roberto Exp roberto $"; 6char *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
198static struct lua_reg mathlib[] = { 199static 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*/
225void mathlib_open (void) 226void 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
diff --git a/strlib.c b/strlib.c
index 3db67936..122a4fb1 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.35 1997/02/21 15:21:34 roberto Exp roberto $"; 6char *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
521void luaI_openlib (struct lua_reg *l, int n) 522static 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
529static 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*/
547void strlib_open (void) 540void 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}