mirror of https://github.com/lua/lua
new header 'auxlib.h' + new function luaL_verror
This commit is contained in:
parent
fa08b42dd8
commit
2de803c250
27
auxlib.c
27
auxlib.c
|
@ -1,20 +1,20 @@
|
|||
char *rcs_auxlib="$Id: $";
|
||||
char *rcs_auxlib="$Id: auxlib.c,v 1.1 1997/03/17 17:02:29 roberto Exp roberto $";
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "auxlib.h"
|
||||
|
||||
|
||||
void luaL_arg_check(int cond, char *funcname, int numarg, char *extramsg)
|
||||
{
|
||||
if (!cond) {
|
||||
char buff[100];
|
||||
if (extramsg == NULL)
|
||||
sprintf(buff, "bad argument #%d to function `%s'", numarg, funcname);
|
||||
luaL_verror("bad argument #%d to function `%s'", numarg, funcname);
|
||||
else
|
||||
sprintf(buff, "bad argument #%d to function `%s' (%s)",
|
||||
luaL_verror("bad argument #%d to function `%s' (%s)",
|
||||
numarg, funcname, extramsg);
|
||||
lua_error(buff);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,3 +45,20 @@ double luaL_opt_number (int numArg, double def, char *funcname)
|
|||
luaL_check_number(numArg, funcname);
|
||||
}
|
||||
|
||||
void luaL_openlib (struct luaL_reg *l, int n)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<n; i++)
|
||||
lua_register(l[i].name, l[i].func);
|
||||
}
|
||||
|
||||
|
||||
void luaL_verror (char *fmt, ...)
|
||||
{
|
||||
char buff[1000];
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
vsprintf(buff, fmt, argp);
|
||||
va_end(argp);
|
||||
lua_error(buff);
|
||||
}
|
||||
|
|
12
iolib.c
12
iolib.c
|
@ -5,6 +5,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "auxlib.h"
|
||||
#include "luadebug.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
@ -234,13 +235,12 @@ static void io_debug (void)
|
|||
|
||||
static void lua_printstack (FILE *f)
|
||||
{
|
||||
int level = 0;
|
||||
int level = 1; /* skip level 0 (it's this function) */
|
||||
lua_Object func;
|
||||
fprintf(f, "Active Stack:\n");
|
||||
while ((func = lua_stackedfunction(level++)) != LUA_NOOBJECT) {
|
||||
char *name;
|
||||
int currentline;
|
||||
fprintf(f, "\t");
|
||||
fprintf(f, (level==2) ? "Active Stack:\n\t" : "\t");
|
||||
switch (*lua_getobjname(func, &name)) {
|
||||
case 'g':
|
||||
fprintf(f, "function %s", name);
|
||||
|
@ -275,7 +275,7 @@ static void errorfb (void)
|
|||
}
|
||||
|
||||
|
||||
static struct lua_reg iolib[] = {
|
||||
static struct luaL_reg iolib[] = {
|
||||
{"readfrom", io_readfrom},
|
||||
{"writeto", io_writeto},
|
||||
{"appendto", io_appendto},
|
||||
|
@ -295,6 +295,6 @@ static struct lua_reg iolib[] = {
|
|||
void iolib_open (void)
|
||||
{
|
||||
lua_infile=stdin; lua_outfile=stdout;
|
||||
luaI_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
|
||||
lua_setfallback("error", errorfb);
|
||||
luaL_openlib(iolib, (sizeof(iolib)/sizeof(iolib[0])));
|
||||
lua_setglobalmethod("error", errorfb);
|
||||
}
|
||||
|
|
7
lex.c
7
lex.c
|
@ -1,9 +1,10 @@
|
|||
char *rcs_lex = "$Id: lex.c,v 2.41 1996/11/22 13:08:02 roberto Exp roberto $";
|
||||
char *rcs_lex = "$Id: lex.c,v 2.42 1997/02/07 13:49:46 roberto Exp roberto $";
|
||||
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "auxlib.h"
|
||||
#include "mem.h"
|
||||
#include "tree.h"
|
||||
#include "table.h"
|
||||
|
@ -32,10 +33,8 @@ void lua_setinput (Input fn)
|
|||
|
||||
static void luaI_auxsyntaxerror (char *s, char *token)
|
||||
{
|
||||
char msg[256];
|
||||
sprintf (msg,"%s;\n> last token read: \"%s\" at line %d in file %s",
|
||||
luaL_verror("%s;\n> last token read: \"%s\" at line %d in file %s",
|
||||
s, token, lua_linenumber, lua_parsedfile);
|
||||
lua_error (msg);
|
||||
}
|
||||
|
||||
void luaI_syntaxerror (char *s)
|
||||
|
|
9
lualib.h
9
lualib.h
|
@ -2,7 +2,7 @@
|
|||
** Libraries to be used in LUA programs
|
||||
** Grupo de Tecnologia em Computacao Grafica
|
||||
** TeCGraf - PUC-Rio
|
||||
** $Id: lualib.h,v 1.10 1996/08/05 20:55:24 roberto Exp roberto $
|
||||
** $Id: lualib.h,v 1.11 1997/03/17 17:01:10 roberto Exp roberto $
|
||||
*/
|
||||
|
||||
#ifndef lualib_h
|
||||
|
@ -15,14 +15,9 @@ 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);
|
||||
char *luaI_addchar (int c);
|
||||
void luaI_addquoted (char *s);
|
||||
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
** Mathematics library to LUA
|
||||
*/
|
||||
|
||||
char *rcs_mathlib="$Id: mathlib.c,v 1.18 1996/08/01 14:55:33 roberto Exp roberto $";
|
||||
char *rcs_mathlib="$Id: mathlib.c,v 1.19 1997/03/17 17:01:10 roberto Exp roberto $";
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "lualib.h"
|
||||
#include "auxlib.h"
|
||||
#include "lua.h"
|
||||
|
||||
#ifndef PI
|
||||
|
@ -195,7 +196,7 @@ static void math_randomseed (void)
|
|||
}
|
||||
|
||||
|
||||
static struct lua_reg mathlib[] = {
|
||||
static struct luaL_reg mathlib[] = {
|
||||
{"abs", math_abs},
|
||||
{"sin", math_sin},
|
||||
{"cos", math_cos},
|
||||
|
@ -224,7 +225,7 @@ static struct lua_reg mathlib[] = {
|
|||
*/
|
||||
void mathlib_open (void)
|
||||
{
|
||||
luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
|
||||
luaL_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0])));
|
||||
old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1);
|
||||
}
|
||||
|
||||
|
|
15
strlib.c
15
strlib.c
|
@ -3,7 +3,7 @@
|
|||
** String library to LUA
|
||||
*/
|
||||
|
||||
char *rcs_strlib="$Id: strlib.c,v 1.35 1997/02/21 15:21:34 roberto Exp roberto $";
|
||||
char *rcs_strlib="$Id: strlib.c,v 1.36 1997/03/17 17:01:10 roberto Exp roberto $";
|
||||
|
||||
#include <string.h>
|
||||
#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 $
|
|||
#include <ctype.h>
|
||||
|
||||
#include "lua.h"
|
||||
#include "auxlib.h"
|
||||
#include "lualib.h"
|
||||
|
||||
|
||||
|
@ -518,15 +519,7 @@ 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[] = {
|
||||
static struct luaL_reg strlib[] = {
|
||||
{"strtok", str_tok},
|
||||
{"strlen", str_len},
|
||||
{"strsub", str_sub},
|
||||
|
@ -546,5 +539,5 @@ static struct lua_reg strlib[] = {
|
|||
*/
|
||||
void strlib_open (void)
|
||||
{
|
||||
luaI_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0])));
|
||||
luaL_openlib(strlib, (sizeof(strlib)/sizeof(strlib[0])));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue