diff options
| -rw-r--r-- | iolib.c | 44 | ||||
| -rw-r--r-- | lualib.h | 11 | ||||
| -rw-r--r-- | mathlib.c | 51 | ||||
| -rw-r--r-- | strlib.c | 28 |
4 files changed, 79 insertions, 55 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: iolib.c,v 1.41 1996/04/22 19:28:37 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.42 1996/04/23 12:43:07 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <ctype.h> | 9 | #include <ctype.h> |
| @@ -593,27 +593,27 @@ static void errorfb (void) | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | 595 | ||
| 596 | /* | 596 | static struct lua_reg iolib[] = { |
| 597 | ** Open io library | 597 | {"readfrom", io_readfrom}, |
| 598 | */ | 598 | {"writeto", io_writeto}, |
| 599 | {"appendto", io_appendto}, | ||
| 600 | {"read", io_read}, | ||
| 601 | {"readuntil",io_readuntil}, | ||
| 602 | {"write", io_write}, | ||
| 603 | {"execute", io_execute}, | ||
| 604 | {"remove", io_remove}, | ||
| 605 | {"rename", io_rename}, | ||
| 606 | {"tmpname", io_tmpname}, | ||
| 607 | {"ioerror", io_errorno}, | ||
| 608 | {"getenv", io_getenv}, | ||
| 609 | {"date", io_date}, | ||
| 610 | {"exit", io_exit}, | ||
| 611 | {"debug", io_debug}, | ||
| 612 | {"print_stack", errorfb} | ||
| 613 | }; | ||
| 614 | |||
| 599 | void iolib_open (void) | 615 | void iolib_open (void) |
| 600 | { | 616 | { |
| 601 | lua_register ("readfrom", io_readfrom); | 617 | luaI_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0]))); |
| 602 | lua_register ("writeto", io_writeto); | 618 | lua_setfallback("error", errorfb); |
| 603 | lua_register ("appendto", io_appendto); | ||
| 604 | lua_register ("read", io_read); | ||
| 605 | lua_register ("readuntil",io_readuntil); | ||
| 606 | lua_register ("write", io_write); | ||
| 607 | lua_register ("execute", io_execute); | ||
| 608 | lua_register ("remove", io_remove); | ||
| 609 | lua_register ("rename", io_rename); | ||
| 610 | lua_register ("tmpname", io_tmpname); | ||
| 611 | lua_register ("ioerror", io_errorno); | ||
| 612 | lua_register ("getenv", io_getenv); | ||
| 613 | lua_register ("date", io_date); | ||
| 614 | lua_register ("exit", io_exit); | ||
| 615 | lua_register ("debug", io_debug); | ||
| 616 | lua_register ("print_stack", errorfb); | ||
| 617 | lua_setfallback("error", errorfb); | ||
| 618 | } | 619 | } |
| 619 | |||
| @@ -2,18 +2,27 @@ | |||
| 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.6 1996/02/09 19:00:23 roberto Exp roberto $ | 5 | ** $Id: lualib.h,v 1.7 1996/03/14 15:53:09 roberto Exp roberto $ |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | #ifndef lualib_h | 8 | #ifndef lualib_h |
| 9 | #define lualib_h | 9 | #define lualib_h |
| 10 | 10 | ||
| 11 | #include "lua.h" | ||
| 12 | |||
| 11 | void iolib_open (void); | 13 | void iolib_open (void); |
| 12 | void strlib_open (void); | 14 | void strlib_open (void); |
| 13 | void mathlib_open (void); | 15 | void mathlib_open (void); |
| 14 | 16 | ||
| 15 | 17 | ||
| 16 | /* auxiliar functions (private) */ | 18 | /* auxiliar functions (private) */ |
| 19 | |||
| 20 | struct lua_reg { | ||
| 21 | char *name; | ||
| 22 | lua_CFunction func; | ||
| 23 | }; | ||
| 24 | |||
| 25 | void luaI_openlib (struct lua_reg *l, int n); | ||
| 17 | void lua_arg_error(char *funcname); | 26 | void lua_arg_error(char *funcname); |
| 18 | char *lua_check_string (int numArg, char *funcname); | 27 | char *lua_check_string (int numArg, char *funcname); |
| 19 | double lua_check_number (int numArg, char *funcname); | 28 | double lua_check_number (int numArg, char *funcname); |
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Mathematics library to LUA | 3 | ** Mathematics library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.15 1996/04/22 18:00:37 roberto Exp roberto $"; | 6 | char *rcs_mathlib="$Id: mathlib.c,v 1.16 1996/04/25 14:10:00 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <math.h> | 9 | #include <math.h> |
| @@ -195,33 +195,36 @@ static void math_randomseed (void) | |||
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | 197 | ||
| 198 | static struct lua_reg mathlib[] = { | ||
| 199 | {"abs", math_abs}, | ||
| 200 | {"sin", math_sin}, | ||
| 201 | {"cos", math_cos}, | ||
| 202 | {"tan", math_tan}, | ||
| 203 | {"asin", math_asin}, | ||
| 204 | {"acos", math_acos}, | ||
| 205 | {"atan", math_atan}, | ||
| 206 | {"atan2", math_atan2}, | ||
| 207 | {"ceil", math_ceil}, | ||
| 208 | {"floor", math_floor}, | ||
| 209 | {"mod", math_mod}, | ||
| 210 | {"sqrt", math_sqrt}, | ||
| 211 | {"min", math_min}, | ||
| 212 | {"max", math_max}, | ||
| 213 | {"log", math_log}, | ||
| 214 | {"log10", math_log10}, | ||
| 215 | {"exp", math_exp}, | ||
| 216 | {"deg", math_deg}, | ||
| 217 | {"rad", math_rad}, | ||
| 218 | {"random", math_random}, | ||
| 219 | {"randomseed", math_randomseed} | ||
| 220 | }; | ||
| 198 | 221 | ||
| 199 | /* | 222 | /* |
| 200 | ** Open math library | 223 | ** Open math library |
| 201 | */ | 224 | */ |
| 202 | void mathlib_open (void) | 225 | void mathlib_open (void) |
| 203 | { | 226 | { |
| 204 | lua_register ("abs", math_abs); | 227 | luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); |
| 205 | lua_register ("sin", math_sin); | 228 | old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); |
| 206 | lua_register ("cos", math_cos); | ||
| 207 | lua_register ("tan", math_tan); | ||
| 208 | lua_register ("asin", math_asin); | ||
| 209 | lua_register ("acos", math_acos); | ||
| 210 | lua_register ("atan", math_atan); | ||
| 211 | lua_register ("atan2", math_atan2); | ||
| 212 | lua_register ("ceil", math_ceil); | ||
| 213 | lua_register ("floor", math_floor); | ||
| 214 | lua_register ("mod", math_mod); | ||
| 215 | lua_register ("sqrt", math_sqrt); | ||
| 216 | lua_register ("min", math_min); | ||
| 217 | lua_register ("max", math_max); | ||
| 218 | lua_register ("log", math_log); | ||
| 219 | lua_register ("log10", math_log10); | ||
| 220 | lua_register ("exp", math_exp); | ||
| 221 | lua_register ("deg", math_deg); | ||
| 222 | lua_register ("rad", math_rad); | ||
| 223 | lua_register ("random", math_random); | ||
| 224 | lua_register ("randomseed", math_randomseed); | ||
| 225 | |||
| 226 | old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); | ||
| 227 | } | 229 | } |
| 230 | |||
| @@ -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.21 1996/03/21 22:18:08 roberto Exp roberto $"; | 6 | char *rcs_strlib="$Id: strlib.c,v 1.22 1996/03/22 17:57:24 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <string.h> | 8 | #include <string.h> |
| 9 | #include <stdio.h> | 9 | #include <stdio.h> |
| @@ -249,16 +249,28 @@ static void str_format (void) | |||
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | 251 | ||
| 252 | void luaI_openlib (struct lua_reg *l, int n) | ||
| 253 | { | ||
| 254 | int i; | ||
| 255 | for (i=0; i<n; i++) | ||
| 256 | lua_register(l[i].name, l[i].func); | ||
| 257 | } | ||
| 258 | |||
| 259 | static struct lua_reg strlib[] = { | ||
| 260 | {"strfind", str_find}, | ||
| 261 | {"strlen", str_len}, | ||
| 262 | {"strsub", str_sub}, | ||
| 263 | {"strlower", str_lower}, | ||
| 264 | {"strupper", str_upper}, | ||
| 265 | {"ascii", str_ascii}, | ||
| 266 | {"format", str_format} | ||
| 267 | }; | ||
| 268 | |||
| 269 | |||
| 252 | /* | 270 | /* |
| 253 | ** Open string library | 271 | ** Open string library |
| 254 | */ | 272 | */ |
| 255 | void strlib_open (void) | 273 | void strlib_open (void) |
| 256 | { | 274 | { |
| 257 | lua_register ("strfind", str_find); | 275 | luaI_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0]))); |
| 258 | lua_register ("strlen", str_len); | ||
| 259 | lua_register ("strsub", str_sub); | ||
| 260 | lua_register ("strlower", str_lower); | ||
| 261 | lua_register ("strupper", str_upper); | ||
| 262 | lua_register ("ascii", str_ascii); | ||
| 263 | lua_register ("format", str_format); | ||
| 264 | } | 276 | } |
