diff options
Diffstat (limited to '')
| -rw-r--r-- | lauxlib.c | 43 |
1 files changed, 22 insertions, 21 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.46 2001/02/02 19:02:40 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.47 2001/02/14 17:04:11 roberto Exp roberto $ |
| 3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -18,10 +18,11 @@ | |||
| 18 | 18 | ||
| 19 | #include "lauxlib.h" | 19 | #include "lauxlib.h" |
| 20 | #include "luadebug.h" | 20 | #include "luadebug.h" |
| 21 | #include "lualib.h" | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | 24 | ||
| 24 | LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | 25 | LUALIB_API int luaL_findstring (const l_char *name, const l_char *const list[]) { |
| 25 | int i; | 26 | int i; |
| 26 | for (i=0; list[i]; i++) | 27 | for (i=0; list[i]; i++) |
| 27 | if (strcmp(list[i], name) == 0) | 28 | if (strcmp(list[i], name) == 0) |
| @@ -29,20 +30,20 @@ LUALIB_API int luaL_findstring (const char *name, const char *const list[]) { | |||
| 29 | return -1; /* name not found */ | 30 | return -1; /* name not found */ |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) { | 33 | LUALIB_API void luaL_argerror (lua_State *L, int narg, const l_char *extramsg) { |
| 33 | lua_Debug ar; | 34 | lua_Debug ar; |
| 34 | lua_getstack(L, 0, &ar); | 35 | lua_getstack(L, 0, &ar); |
| 35 | lua_getinfo(L, "n", &ar); | 36 | lua_getinfo(L, l_s("n"), &ar); |
| 36 | if (ar.name == NULL) | 37 | if (ar.name == NULL) |
| 37 | ar.name = "?"; | 38 | ar.name = l_s("?"); |
| 38 | luaL_verror(L, "bad argument #%d to `%.50s' (%.100s)", | 39 | luaL_verror(L, l_s("bad argument #%d to `%.50s' (%.100s)"), |
| 39 | narg, ar.name, extramsg); | 40 | narg, ar.name, extramsg); |
| 40 | } | 41 | } |
| 41 | 42 | ||
| 42 | 43 | ||
| 43 | static void type_error (lua_State *L, int narg, const char *tname) { | 44 | static void type_error (lua_State *L, int narg, const l_char *tname) { |
| 44 | char buff[80]; | 45 | l_char buff[80]; |
| 45 | sprintf(buff, "%.25s expected, got %.25s", tname, lua_xtype(L, narg)); | 46 | sprintf(buff, l_s("%.25s expected, got %.25s"), tname, lua_xtype(L, narg)); |
| 46 | luaL_argerror(L, narg, buff); | 47 | luaL_argerror(L, narg, buff); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| @@ -52,9 +53,9 @@ static void tag_error (lua_State *L, int narg, int tag) { | |||
| 52 | } | 53 | } |
| 53 | 54 | ||
| 54 | 55 | ||
| 55 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) { | 56 | LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *mes) { |
| 56 | if (space > lua_stackspace(L)) | 57 | if (space > lua_stackspace(L)) |
| 57 | luaL_verror(L, "stack overflow (%.30s)", mes); | 58 | luaL_verror(L, l_s("stack overflow (%.30s)"), mes); |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | 61 | ||
| @@ -66,27 +67,27 @@ LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) { | |||
| 66 | 67 | ||
| 67 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { | 68 | LUALIB_API void luaL_checkany (lua_State *L, int narg) { |
| 68 | if (lua_type(L, narg) == LUA_TNONE) | 69 | if (lua_type(L, narg) == LUA_TNONE) |
| 69 | luaL_argerror(L, narg, "value expected"); | 70 | luaL_argerror(L, narg, l_s("value expected")); |
| 70 | } | 71 | } |
| 71 | 72 | ||
| 72 | 73 | ||
| 73 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, | 74 | LUALIB_API void *luaL_check_userdata (lua_State *L, int narg, |
| 74 | const char *name) { | 75 | const l_char *name) { |
| 75 | if (strcmp(lua_xtype(L, narg), name) != 0) | 76 | if (strcmp(lua_xtype(L, narg), name) != 0) |
| 76 | type_error(L, narg, name); | 77 | type_error(L, narg, name); |
| 77 | return lua_touserdata(L, narg); | 78 | return lua_touserdata(L, narg); |
| 78 | } | 79 | } |
| 79 | 80 | ||
| 80 | 81 | ||
| 81 | LUALIB_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { | 82 | LUALIB_API const l_char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { |
| 82 | const char *s = lua_tostring(L, narg); | 83 | const l_char *s = lua_tostring(L, narg); |
| 83 | if (!s) tag_error(L, narg, LUA_TSTRING); | 84 | if (!s) tag_error(L, narg, LUA_TSTRING); |
| 84 | if (len) *len = lua_strlen(L, narg); | 85 | if (len) *len = lua_strlen(L, narg); |
| 85 | return s; | 86 | return s; |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 88 | 89 | ||
| 89 | LUALIB_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, size_t *len) { | 90 | LUALIB_API const l_char *luaL_opt_lstr (lua_State *L, int narg, const l_char *def, size_t *len) { |
| 90 | if (lua_isnull(L, narg)) { | 91 | if (lua_isnull(L, narg)) { |
| 91 | if (len) | 92 | if (len) |
| 92 | *len = (def ? strlen(def) : 0); | 93 | *len = (def ? strlen(def) : 0); |
| @@ -117,8 +118,8 @@ LUALIB_API void luaL_openlib (lua_State *L, const luaL_reg *l, int n) { | |||
| 117 | } | 118 | } |
| 118 | 119 | ||
| 119 | 120 | ||
| 120 | LUALIB_API void luaL_verror (lua_State *L, const char *fmt, ...) { | 121 | LUALIB_API void luaL_verror (lua_State *L, const l_char *fmt, ...) { |
| 121 | char buff[500]; | 122 | l_char buff[500]; |
| 122 | va_list argp; | 123 | va_list argp; |
| 123 | va_start(argp, fmt); | 124 | va_start(argp, fmt); |
| 124 | vsprintf(buff, fmt, argp); | 125 | vsprintf(buff, fmt, argp); |
| @@ -172,20 +173,20 @@ static void adjuststack (luaL_Buffer *B) { | |||
| 172 | } | 173 | } |
| 173 | 174 | ||
| 174 | 175 | ||
| 175 | LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B) { | 176 | LUALIB_API l_char *luaL_prepbuffer (luaL_Buffer *B) { |
| 176 | if (emptybuffer(B)) | 177 | if (emptybuffer(B)) |
| 177 | adjuststack(B); | 178 | adjuststack(B); |
| 178 | return B->buffer; | 179 | return B->buffer; |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | 182 | ||
| 182 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { | 183 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const l_char *s, size_t l) { |
| 183 | while (l--) | 184 | while (l--) |
| 184 | luaL_putchar(B, *s++); | 185 | luaL_putchar(B, *s++); |
| 185 | } | 186 | } |
| 186 | 187 | ||
| 187 | 188 | ||
| 188 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { | 189 | LUALIB_API void luaL_addstring (luaL_Buffer *B, const l_char *s) { |
| 189 | luaL_addlstring(B, s, strlen(s)); | 190 | luaL_addlstring(B, s, strlen(s)); |
| 190 | } | 191 | } |
| 191 | 192 | ||
