summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--iolib.c44
-rw-r--r--lualib.h11
-rw-r--r--mathlib.c51
-rw-r--r--strlib.c28
4 files changed, 79 insertions, 55 deletions
diff --git a/iolib.c b/iolib.c
index cdbe3447..a5c26a0e 100644
--- a/iolib.c
+++ b/iolib.c
@@ -3,7 +3,7 @@
** Input/output library to LUA
*/
-char *rcs_iolib="$Id: iolib.c,v 1.41 1996/04/22 19:28:37 roberto Exp roberto $";
+char *rcs_iolib="$Id: iolib.c,v 1.42 1996/04/23 12:43:07 roberto Exp roberto $";
#include <stdio.h>
#include <ctype.h>
@@ -593,27 +593,27 @@ static void errorfb (void)
}
-/*
-** Open io library
-*/
+static struct lua_reg iolib[] = {
+{"readfrom", io_readfrom},
+{"writeto", io_writeto},
+{"appendto", io_appendto},
+{"read", io_read},
+{"readuntil",io_readuntil},
+{"write", io_write},
+{"execute", io_execute},
+{"remove", io_remove},
+{"rename", io_rename},
+{"tmpname", io_tmpname},
+{"ioerror", io_errorno},
+{"getenv", io_getenv},
+{"date", io_date},
+{"exit", io_exit},
+{"debug", io_debug},
+{"print_stack", errorfb}
+};
+
void iolib_open (void)
{
- lua_register ("readfrom", io_readfrom);
- lua_register ("writeto", io_writeto);
- lua_register ("appendto", io_appendto);
- lua_register ("read", io_read);
- lua_register ("readuntil",io_readuntil);
- lua_register ("write", io_write);
- lua_register ("execute", io_execute);
- lua_register ("remove", io_remove);
- lua_register ("rename", io_rename);
- lua_register ("tmpname", io_tmpname);
- lua_register ("ioerror", io_errorno);
- lua_register ("getenv", io_getenv);
- lua_register ("date", io_date);
- lua_register ("exit", io_exit);
- lua_register ("debug", io_debug);
- lua_register ("print_stack", errorfb);
- lua_setfallback("error", errorfb);
+ luaI_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
+ lua_setfallback("error", errorfb);
}
-
diff --git a/lualib.h b/lualib.h
index d7403b5f..567b0269 100644
--- a/lualib.h
+++ b/lualib.h
@@ -2,18 +2,27 @@
** Libraries to be used in LUA programs
** Grupo de Tecnologia em Computacao Grafica
** TeCGraf - PUC-Rio
-** $Id: lualib.h,v 1.6 1996/02/09 19:00:23 roberto Exp roberto $
+** $Id: lualib.h,v 1.7 1996/03/14 15:53:09 roberto Exp roberto $
*/
#ifndef lualib_h
#define lualib_h
+#include "lua.h"
+
void iolib_open (void);
void strlib_open (void);
void mathlib_open (void);
/* auxiliar functions (private) */
+
+struct lua_reg {
+ char *name;
+ lua_CFunction func;
+};
+
+void luaI_openlib (struct lua_reg *l, int n);
void lua_arg_error(char *funcname);
char *lua_check_string (int numArg, char *funcname);
double lua_check_number (int numArg, char *funcname);
diff --git a/mathlib.c b/mathlib.c
index 5e02908e..f01e149d 100644
--- a/mathlib.c
+++ b/mathlib.c
@@ -3,7 +3,7 @@
** Mathematics library to LUA
*/
-char *rcs_mathlib="$Id: mathlib.c,v 1.15 1996/04/22 18:00:37 roberto Exp roberto $";
+char *rcs_mathlib="$Id: mathlib.c,v 1.16 1996/04/25 14:10:00 roberto Exp roberto $";
#include <stdlib.h>
#include <math.h>
@@ -195,33 +195,36 @@ static void math_randomseed (void)
}
+static struct lua_reg mathlib[] = {
+{"abs", math_abs},
+{"sin", math_sin},
+{"cos", math_cos},
+{"tan", math_tan},
+{"asin", math_asin},
+{"acos", math_acos},
+{"atan", math_atan},
+{"atan2", math_atan2},
+{"ceil", math_ceil},
+{"floor", math_floor},
+{"mod", math_mod},
+{"sqrt", math_sqrt},
+{"min", math_min},
+{"max", math_max},
+{"log", math_log},
+{"log10", math_log10},
+{"exp", math_exp},
+{"deg", math_deg},
+{"rad", math_rad},
+{"random", math_random},
+{"randomseed", math_randomseed}
+};
/*
** Open math library
*/
void mathlib_open (void)
{
- lua_register ("abs", math_abs);
- lua_register ("sin", math_sin);
- lua_register ("cos", math_cos);
- lua_register ("tan", math_tan);
- lua_register ("asin", math_asin);
- lua_register ("acos", math_acos);
- lua_register ("atan", math_atan);
- lua_register ("atan2", math_atan2);
- lua_register ("ceil", math_ceil);
- lua_register ("floor", math_floor);
- lua_register ("mod", math_mod);
- lua_register ("sqrt", math_sqrt);
- lua_register ("min", math_min);
- lua_register ("max", math_max);
- lua_register ("log", math_log);
- lua_register ("log10", math_log10);
- lua_register ("exp", math_exp);
- lua_register ("deg", math_deg);
- lua_register ("rad", math_rad);
- lua_register ("random", math_random);
- lua_register ("randomseed", math_randomseed);
-
- old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
+ luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
+ old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
}
+
diff --git a/strlib.c b/strlib.c
index 9d084b36..a3467050 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
** String library to LUA
*/
-char *rcs_strlib="$Id: strlib.c,v 1.21 1996/03/21 22:18:08 roberto Exp roberto $";
+char *rcs_strlib="$Id: strlib.c,v 1.22 1996/03/22 17:57:24 roberto Exp roberto $";
#include <string.h>
#include <stdio.h>
@@ -249,16 +249,28 @@ static void str_format (void)
}
+void luaI_openlib (struct lua_reg *l, int n)
+{
+ int i;
+ for (i=0; i<n; i++)
+ lua_register(l[i].name, l[i].func);
+}
+
+static struct lua_reg strlib[] = {
+{"strfind", str_find},
+{"strlen", str_len},
+{"strsub", str_sub},
+{"strlower", str_lower},
+{"strupper", str_upper},
+{"ascii", str_ascii},
+{"format", str_format}
+};
+
+
/*
** Open string library
*/
void strlib_open (void)
{
- lua_register ("strfind", str_find);
- lua_register ("strlen", str_len);
- lua_register ("strsub", str_sub);
- lua_register ("strlower", str_lower);
- lua_register ("strupper", str_upper);
- lua_register ("ascii", str_ascii);
- lua_register ("format", str_format);
+ luaI_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0])));
}