Skip to content

Commit

Permalink
new macro LUALIB_API (so the lib can be a separate DLL)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-ieru committed Oct 27, 2000
1 parent e2b6b7d commit 2cbbf39
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 52 deletions.
36 changes: 18 additions & 18 deletions lauxlib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.c,v 1.39 2000/10/05 12:14:08 roberto Exp roberto $
** $Id: lauxlib.c,v 1.40 2000/10/20 16:39:03 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
Expand All @@ -21,15 +21,15 @@



LUA_API int luaL_findstring (const char *name, const char *const list[]) {
LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
int i;
for (i=0; list[i]; i++)
if (strcmp(list[i], name) == 0)
return i;
return -1; /* name not found */
}

LUA_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
lua_Debug ar;
lua_getstack(L, 0, &ar);
lua_getinfo(L, "n", &ar);
Expand All @@ -49,33 +49,33 @@ static void type_error (lua_State *L, int narg, int t) {
}


LUA_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
if (space > lua_stackspace(L))
luaL_verror(L, "stack overflow (%.30s)", mes);
}


LUA_API void luaL_checktype(lua_State *L, int narg, int t) {
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) {
if (lua_type(L, narg) != t)
type_error(L, narg, t);
}


LUA_API void luaL_checkany (lua_State *L, int narg) {
LUALIB_API void luaL_checkany (lua_State *L, int narg) {
if (lua_type(L, narg) == LUA_TNONE)
luaL_argerror(L, narg, "value expected");
}


LUA_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
const char *s = lua_tostring(L, narg);
if (!s) type_error(L, narg, LUA_TSTRING);
if (len) *len = lua_strlen(L, narg);
return s;
}


LUA_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
size_t *len) {
if (lua_isnull(L, narg)) {
if (len)
Expand All @@ -86,28 +86,28 @@ LUA_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
}


LUA_API double luaL_check_number (lua_State *L, int narg) {
LUALIB_API double luaL_check_number (lua_State *L, int narg) {
double d = lua_tonumber(L, narg);
if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
type_error(L, narg, LUA_TNUMBER);
return d;
}


LUA_API double luaL_opt_number (lua_State *L, int narg, double def) {
LUALIB_API double luaL_opt_number (lua_State *L, int narg, double def) {
if (lua_isnull(L, narg)) return def;
else return luaL_check_number(L, narg);
}


LUA_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) {
LUALIB_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) {
int i;
for (i=0; i<n; i++)
lua_register(L, l[i].name, l[i].func);
}


LUA_API void luaL_verror (lua_State *L, const char *fmt, ...) {
LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) {
char buff[500];
va_list argp;
va_start(argp, fmt);
Expand Down Expand Up @@ -164,25 +164,25 @@ static void adjuststack (luaL_Buffer *B) {
}


LUA_API char *luaL_prepbuffer (luaL_Buffer *B) {
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) {
if (emptybuffer(B))
adjuststack(B);
return B->buffer;
}


LUA_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
while (l--)
luaL_putchar(B, *s++);
}


LUA_API void luaL_addstring (luaL_Buffer *B, const char *s) {
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
luaL_addlstring(B, s, strlen(s));
}


LUA_API void luaL_pushresult (luaL_Buffer *B) {
LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
emptybuffer(B);
if (B->level == 0)
lua_pushlstring(B->L, NULL, 0);
Expand All @@ -192,7 +192,7 @@ LUA_API void luaL_pushresult (luaL_Buffer *B) {
}


LUA_API void luaL_addvalue (luaL_Buffer *B) {
LUALIB_API void luaL_addvalue (luaL_Buffer *B) {
lua_State *L = B->L;
size_t vl = lua_strlen(L, -1);
if (vl <= bufffree(B)) { /* fit into buffer? */
Expand All @@ -209,7 +209,7 @@ LUA_API void luaL_addvalue (luaL_Buffer *B) {
}


LUA_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
B->L = L;
B->p = B->buffer;
B->level = 0;
Expand Down
41 changes: 23 additions & 18 deletions lauxlib.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lauxlib.h,v 1.27 2000/10/05 12:14:08 roberto Exp roberto $
** $Id: lauxlib.h,v 1.28 2000/10/20 16:39:03 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
Expand All @@ -15,26 +15,31 @@
#include "lua.h"


#ifndef LUALIB_API
#define LUALIB_API extern
#endif


struct luaL_reg {
const char *name;
lua_CFunction func;
};


LUA_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
LUA_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
LUA_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
LUA_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def,
LUALIB_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n);
LUALIB_API void luaL_argerror (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *luaL_check_lstr (lua_State *L, int numArg, size_t *len);
LUALIB_API const char *luaL_opt_lstr (lua_State *L, int numArg, const char *def,
size_t *len);
LUA_API double luaL_check_number (lua_State *L, int numArg);
LUA_API double luaL_opt_number (lua_State *L, int numArg, double def);
LUALIB_API double luaL_check_number (lua_State *L, int numArg);
LUALIB_API double luaL_opt_number (lua_State *L, int numArg, double def);

LUA_API void luaL_checkstack (lua_State *L, int space, const char *msg);
LUA_API void luaL_checktype (lua_State *L, int narg, int t);
LUA_API void luaL_checkany (lua_State *L, int narg);
LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *msg);
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
LUALIB_API void luaL_checkany (lua_State *L, int narg);

LUA_API void luaL_verror (lua_State *L, const char *fmt, ...);
LUA_API int luaL_findstring (const char *name, const char *const list[]);
LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...);
LUALIB_API int luaL_findstring (const char *name, const char *const list[]);



Expand Down Expand Up @@ -80,12 +85,12 @@ typedef struct luaL_Buffer {

#define luaL_addsize(B,n) ((B)->p += (n))

LUA_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
LUA_API char *luaL_prepbuffer (luaL_Buffer *B);
LUA_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
LUA_API void luaL_addstring (luaL_Buffer *B, const char *s);
LUA_API void luaL_addvalue (luaL_Buffer *B);
LUA_API void luaL_pushresult (luaL_Buffer *B);
LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B);
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s);
LUALIB_API void luaL_addvalue (luaL_Buffer *B);
LUALIB_API void luaL_pushresult (luaL_Buffer *B);


/* }====================================================== */
Expand Down
4 changes: 2 additions & 2 deletions lbaselib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.13 2000/10/20 16:57:42 roberto Exp roberto $
** $Id: lbaselib.c,v 1.14 2000/10/24 19:19:15 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -639,7 +639,7 @@ static const struct luaL_reg base_funcs[] = {



LUA_API void lua_baselibopen (lua_State *L) {
LUALIB_API void lua_baselibopen (lua_State *L) {
luaL_openl(L, base_funcs);
lua_pushstring(L, LUA_VERSION);
lua_setglobal(L, "_VERSION");
Expand Down
4 changes: 2 additions & 2 deletions ldblib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.25 2000/10/26 18:44:26 roberto Exp roberto $
** $Id: ldblib.c,v 1.26 2000/10/26 19:04:22 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -179,7 +179,7 @@ static const struct luaL_reg dblib[] = {
};


LUA_API void lua_dblibopen (lua_State *L) {
LUALIB_API void lua_dblibopen (lua_State *L) {
luaL_openl(L, dblib);
}

4 changes: 2 additions & 2 deletions liolib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 1.88 2000/10/26 12:47:05 roberto Exp roberto $
** $Id: liolib.c,v 1.89 2000/10/26 12:53:55 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -712,7 +712,7 @@ static void openwithcontrol (lua_State *L) {
}


LUA_API void lua_iolibopen (lua_State *L) {
LUALIB_API void lua_iolibopen (lua_State *L) {
luaL_openl(L, iolib);
openwithcontrol(L);
}
Expand Down
4 changes: 2 additions & 2 deletions lmathlib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.29 2000/10/20 16:39:03 roberto Exp roberto $
** $Id: lmathlib.c,v 1.30 2000/10/26 12:47:05 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -228,7 +228,7 @@ static const struct luaL_reg mathlib[] = {
/*
** Open math library
*/
LUA_API void lua_mathlibopen (lua_State *L) {
LUALIB_API void lua_mathlibopen (lua_State *L) {
luaL_openl(L, mathlib);
lua_pushcfunction(L, math_pow);
lua_settagmethod(L, LUA_TNUMBER, "pow");
Expand Down
4 changes: 2 additions & 2 deletions lstrlib.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.54 2000/10/05 12:14:08 roberto Exp roberto $
** $Id: lstrlib.c,v 1.55 2000/10/20 16:39:03 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
Expand Down Expand Up @@ -616,6 +616,6 @@ static const struct luaL_reg strlib[] = {
/*
** Open string library
*/
LUA_API void lua_strlibopen (lua_State *L) {
LUALIB_API void lua_strlibopen (lua_State *L) {
luaL_openl(L, strlib);
}
17 changes: 11 additions & 6 deletions lualib.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
** $Id: lualib.h,v 1.12 2000/09/12 13:46:59 roberto Exp roberto $
** $Id: lualib.h,v 1.13 2000/10/20 16:39:03 roberto Exp roberto $
** Lua standard libraries
** See Copyright Notice in lua.h
*/
Expand All @@ -11,13 +11,18 @@
#include "lua.h"


#ifndef LUALIB_API
#define LUALIB_API extern
#endif


#define LUA_ALERT "_ALERT"

LUA_API void lua_baselibopen (lua_State *L);
LUA_API void lua_iolibopen (lua_State *L);
LUA_API void lua_strlibopen (lua_State *L);
LUA_API void lua_mathlibopen (lua_State *L);
LUA_API void lua_dblibopen (lua_State *L);
LUALIB_API void lua_baselibopen (lua_State *L);
LUALIB_API void lua_iolibopen (lua_State *L);
LUALIB_API void lua_strlibopen (lua_State *L);
LUALIB_API void lua_mathlibopen (lua_State *L);
LUALIB_API void lua_dblibopen (lua_State *L);



Expand Down

0 comments on commit 2cbbf39

Please sign in to comment.