1997-04-07 18:48:53 +04:00
|
|
|
char *rcs_auxlib="$Id: auxlib.c,v 1.3 1997/04/06 14:08:08 roberto Exp roberto $";
|
1997-03-17 20:02:29 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
1997-03-18 18:30:50 +03:00
|
|
|
#include <stdarg.h>
|
1997-04-07 18:48:53 +04:00
|
|
|
#include <string.h>
|
1997-03-17 20:02:29 +03:00
|
|
|
|
|
|
|
#include "lua.h"
|
1997-03-18 18:30:50 +03:00
|
|
|
#include "auxlib.h"
|
1997-04-06 18:08:08 +04:00
|
|
|
#include "luadebug.h"
|
1997-03-17 20:02:29 +03:00
|
|
|
|
|
|
|
|
1997-04-07 18:48:53 +04:00
|
|
|
|
|
|
|
int luaI_findstring (char *name, char *list[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; list[i]; i++)
|
|
|
|
if (strcmp(list[i], name) == 0)
|
|
|
|
return i;
|
|
|
|
return -1; /* name not found */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-06 18:08:08 +04:00
|
|
|
void luaL_arg_check(int cond, int numarg, char *extramsg)
|
1997-03-17 20:02:29 +03:00
|
|
|
{
|
1997-04-06 18:08:08 +04:00
|
|
|
char *funcname;
|
|
|
|
lua_getobjname(lua_stackedfunction(0), &funcname);
|
|
|
|
if (funcname == NULL)
|
|
|
|
funcname = "???";
|
1997-03-17 20:02:29 +03:00
|
|
|
if (!cond) {
|
|
|
|
if (extramsg == NULL)
|
1997-03-18 18:30:50 +03:00
|
|
|
luaL_verror("bad argument #%d to function `%s'", numarg, funcname);
|
1997-03-17 20:02:29 +03:00
|
|
|
else
|
1997-03-18 18:30:50 +03:00
|
|
|
luaL_verror("bad argument #%d to function `%s' (%s)",
|
1997-03-17 20:02:29 +03:00
|
|
|
numarg, funcname, extramsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-04-06 18:08:08 +04:00
|
|
|
char *luaL_check_string (int numArg)
|
1997-03-17 20:02:29 +03:00
|
|
|
{
|
|
|
|
lua_Object o = lua_getparam(numArg);
|
1997-04-06 18:08:08 +04:00
|
|
|
luaL_arg_check(lua_isstring(o), numArg, "string expected");
|
1997-03-17 20:02:29 +03:00
|
|
|
return lua_getstring(o);
|
|
|
|
}
|
|
|
|
|
1997-04-06 18:08:08 +04:00
|
|
|
char *luaL_opt_string (int numArg, char *def)
|
1997-03-17 20:02:29 +03:00
|
|
|
{
|
|
|
|
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
1997-04-06 18:08:08 +04:00
|
|
|
luaL_check_string(numArg);
|
1997-03-17 20:02:29 +03:00
|
|
|
}
|
|
|
|
|
1997-04-06 18:08:08 +04:00
|
|
|
double luaL_check_number (int numArg)
|
1997-03-17 20:02:29 +03:00
|
|
|
{
|
|
|
|
lua_Object o = lua_getparam(numArg);
|
1997-04-06 18:08:08 +04:00
|
|
|
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
|
1997-03-17 20:02:29 +03:00
|
|
|
return lua_getnumber(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-04-06 18:08:08 +04:00
|
|
|
double luaL_opt_number (int numArg, double def)
|
1997-03-17 20:02:29 +03:00
|
|
|
{
|
|
|
|
return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
|
1997-04-06 18:08:08 +04:00
|
|
|
luaL_check_number(numArg);
|
1997-03-17 20:02:29 +03:00
|
|
|
}
|
|
|
|
|
1997-03-18 18:30:50 +03:00
|
|
|
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);
|
|
|
|
}
|