first implementation of multiple states (reentrant code).
This commit is contained in:
75
lauxlib.c
75
lauxlib.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.19 1999/09/06 13:13:03 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.20 1999/10/05 18:33:43 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@@ -14,6 +14,8 @@
|
||||
** With care, these functions can be used by other libraries.
|
||||
*/
|
||||
|
||||
#define LUA_REENTRANT
|
||||
|
||||
#include "lauxlib.h"
|
||||
#include "lua.h"
|
||||
#include "luadebug.h"
|
||||
@@ -28,87 +30,86 @@ int luaL_findstring (const char *name, const char *const list[]) {
|
||||
return -1; /* name not found */
|
||||
}
|
||||
|
||||
void luaL_argerror (int numarg, const char *extramsg) {
|
||||
lua_Function f = lua_stackedfunction(0);
|
||||
void luaL_argerror (lua_State *L, int numarg, const char *extramsg) {
|
||||
lua_Function f = lua_stackedfunction(L, 0);
|
||||
const char *funcname;
|
||||
lua_getobjname(f, &funcname);
|
||||
numarg -= lua_nups(f);
|
||||
lua_getobjname(L, f, &funcname);
|
||||
numarg -= lua_nups(L, f);
|
||||
if (funcname == NULL)
|
||||
funcname = "?";
|
||||
luaL_verror("bad argument #%d to function `%.50s' (%.100s)",
|
||||
luaL_verror(L, "bad argument #%d to function `%.50s' (%.100s)",
|
||||
numarg, funcname, extramsg);
|
||||
}
|
||||
|
||||
static const char *checkstr (lua_Object o, int numArg, long *len) {
|
||||
const char *s = lua_getstring(o);
|
||||
luaL_arg_check(s, numArg, "string expected");
|
||||
if (len) *len = lua_strlen(o);
|
||||
static const char *checkstr (lua_State *L, lua_Object o, int n, long *len) {
|
||||
const char *s = lua_getstring(L, o);
|
||||
luaL_arg_check(L, s, n, "string expected");
|
||||
if (len) *len = lua_strlen(L, o);
|
||||
return s;
|
||||
}
|
||||
|
||||
const char *luaL_check_lstr (int numArg, long *len) {
|
||||
return checkstr(lua_getparam(numArg), numArg, len);
|
||||
const char *luaL_check_lstr (lua_State *L, int n, long *len) {
|
||||
return checkstr(L, lua_getparam(L, n), n, len);
|
||||
}
|
||||
|
||||
const char *luaL_opt_lstr (int numArg, const char *def, long *len) {
|
||||
lua_Object o = lua_getparam(numArg);
|
||||
const char *luaL_opt_lstr (lua_State *L, int n, const char *def, long *len) {
|
||||
lua_Object o = lua_getparam(L, n);
|
||||
if (o == LUA_NOOBJECT) {
|
||||
if (len) *len = def ? strlen(def) : 0;
|
||||
return def;
|
||||
}
|
||||
else return checkstr(o, numArg, len);
|
||||
else return checkstr(L, o, n, len);
|
||||
}
|
||||
|
||||
double luaL_check_number (int numArg) {
|
||||
lua_Object o = lua_getparam(numArg);
|
||||
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
|
||||
return lua_getnumber(o);
|
||||
double luaL_check_number (lua_State *L, int n) {
|
||||
lua_Object o = lua_getparam(L, n);
|
||||
luaL_arg_check(L, lua_isnumber(L, o), n, "number expected");
|
||||
return lua_getnumber(L, o);
|
||||
}
|
||||
|
||||
|
||||
double luaL_opt_number (int numArg, double def) {
|
||||
lua_Object o = lua_getparam(numArg);
|
||||
double luaL_opt_number (lua_State *L, int n, double def) {
|
||||
lua_Object o = lua_getparam(L, n);
|
||||
if (o == LUA_NOOBJECT) return def;
|
||||
else {
|
||||
luaL_arg_check(lua_isnumber(o), numArg, "number expected");
|
||||
return lua_getnumber(o);
|
||||
luaL_arg_check(L, lua_isnumber(L, o), n, "number expected");
|
||||
return lua_getnumber(L, o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lua_Object luaL_tablearg (int arg) {
|
||||
lua_Object o = lua_getparam(arg);
|
||||
luaL_arg_check(lua_istable(o), arg, "table expected");
|
||||
lua_Object luaL_tablearg (lua_State *L, int arg) {
|
||||
lua_Object o = lua_getparam(L, arg);
|
||||
luaL_arg_check(L, lua_istable(L, o), arg, "table expected");
|
||||
return o;
|
||||
}
|
||||
|
||||
lua_Object luaL_functionarg (int arg) {
|
||||
lua_Object o = lua_getparam(arg);
|
||||
luaL_arg_check(lua_isfunction(o), arg, "function expected");
|
||||
lua_Object luaL_functionarg (lua_State *L, int arg) {
|
||||
lua_Object o = lua_getparam(L, arg);
|
||||
luaL_arg_check(L, lua_isfunction(L, o), arg, "function expected");
|
||||
return o;
|
||||
}
|
||||
|
||||
lua_Object luaL_nonnullarg (int numArg) {
|
||||
lua_Object o = lua_getparam(numArg);
|
||||
luaL_arg_check(o != LUA_NOOBJECT, numArg, "value expected");
|
||||
lua_Object luaL_nonnullarg (lua_State *L, int n) {
|
||||
lua_Object o = lua_getparam(L, n);
|
||||
luaL_arg_check(L, o != LUA_NOOBJECT, n, "value expected");
|
||||
return o;
|
||||
}
|
||||
|
||||
void luaL_openlib (const struct luaL_reg *l, int n) {
|
||||
void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) {
|
||||
int i;
|
||||
lua_open(); /* make sure lua is already open */
|
||||
for (i=0; i<n; i++)
|
||||
lua_register(l[i].name, l[i].func);
|
||||
lua_register(L, l[i].name, l[i].func);
|
||||
}
|
||||
|
||||
|
||||
void luaL_verror (const char *fmt, ...) {
|
||||
void luaL_verror (lua_State *L, const char *fmt, ...) {
|
||||
char buff[500];
|
||||
va_list argp;
|
||||
va_start(argp, fmt);
|
||||
vsprintf(buff, fmt, argp);
|
||||
va_end(argp);
|
||||
lua_error(buff);
|
||||
lua_error(L, buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user