aboutsummaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-20 14:39:03 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2000-10-20 14:39:03 -0200
commit64eecc0b8219cc3bcaa2b717826a4376c60d9305 (patch)
treea1633501cdf21016a00bd555c475daea58ec24f5 /lauxlib.c
parent8b88ab07f7cfc216407a88d75ad8f0546224c8d7 (diff)
downloadlua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.tar.gz
lua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.tar.bz2
lua-64eecc0b8219cc3bcaa2b717826a4376c60d9305.zip
new macro LUA_API
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 433c24df..08ad3fba 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.38 2000/10/02 20:10:55 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.39 2000/10/05 12:14:08 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*/
@@ -21,7 +21,7 @@
21 21
22 22
23 23
24int luaL_findstring (const char *name, const char *const list[]) { 24LUA_API int luaL_findstring (const char *name, const char *const list[]) {
25 int i; 25 int i;
26 for (i=0; list[i]; i++) 26 for (i=0; list[i]; i++)
27 if (strcmp(list[i], name) == 0) 27 if (strcmp(list[i], name) == 0)
@@ -29,7 +29,7 @@ int luaL_findstring (const char *name, const char *const list[]) {
29 return -1; /* name not found */ 29 return -1; /* name not found */
30} 30}
31 31
32void luaL_argerror (lua_State *L, int narg, const char *extramsg) { 32LUA_API void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
33 lua_Debug ar; 33 lua_Debug ar;
34 lua_getstack(L, 0, &ar); 34 lua_getstack(L, 0, &ar);
35 lua_getinfo(L, "n", &ar); 35 lua_getinfo(L, "n", &ar);
@@ -42,32 +42,32 @@ void luaL_argerror (lua_State *L, int narg, const char *extramsg) {
42 42
43static void type_error (lua_State *L, int narg, int t) { 43static void type_error (lua_State *L, int narg, int t) {
44 char buff[100]; 44 char buff[100];
45 const char *rt = lua_typename(L, lua_type(L, narg)); 45 int tt = lua_type(L, narg);
46 if (*rt == 'N') rt = "no value"; 46 const char *rt = (tt == LUA_TNONE) ? "no value" : lua_typename(L, tt);
47 sprintf(buff, "%.10s expected, got %.10s", lua_typename(L, t), rt); 47 sprintf(buff, "%.10s expected, got %.10s", lua_typename(L, t), rt);
48 luaL_argerror(L, narg, buff); 48 luaL_argerror(L, narg, buff);
49} 49}
50 50
51 51
52void luaL_checkstack (lua_State *L, int space, const char *mes) { 52LUA_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
53 if (space > lua_stackspace(L)) 53 if (space > lua_stackspace(L))
54 luaL_verror(L, "stack overflow (%.30s)", mes); 54 luaL_verror(L, "stack overflow (%.30s)", mes);
55} 55}
56 56
57 57
58void luaL_checktype(lua_State *L, int narg, int t) { 58LUA_API void luaL_checktype(lua_State *L, int narg, int t) {
59 if (lua_type(L, narg) != t) 59 if (lua_type(L, narg) != t)
60 type_error(L, narg, t); 60 type_error(L, narg, t);
61} 61}
62 62
63 63
64void luaL_checkany (lua_State *L, int narg) { 64LUA_API void luaL_checkany (lua_State *L, int narg) {
65 if (lua_type(L, narg) == LUA_TNONE) 65 if (lua_type(L, narg) == LUA_TNONE)
66 luaL_argerror(L, narg, "value expected"); 66 luaL_argerror(L, narg, "value expected");
67} 67}
68 68
69 69
70const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) { 70LUA_API const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
71 const char *s = lua_tostring(L, narg); 71 const char *s = lua_tostring(L, narg);
72 if (!s) type_error(L, narg, LUA_TSTRING); 72 if (!s) type_error(L, narg, LUA_TSTRING);
73 if (len) *len = lua_strlen(L, narg); 73 if (len) *len = lua_strlen(L, narg);
@@ -75,7 +75,7 @@ const char *luaL_check_lstr (lua_State *L, int narg, size_t *len) {
75} 75}
76 76
77 77
78const char *luaL_opt_lstr (lua_State *L, int narg, const char *def, 78LUA_API const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
79 size_t *len) { 79 size_t *len) {
80 if (lua_isnull(L, narg)) { 80 if (lua_isnull(L, narg)) {
81 if (len) 81 if (len)
@@ -86,7 +86,7 @@ const char *luaL_opt_lstr (lua_State *L, int narg, const char *def,
86} 86}
87 87
88 88
89double luaL_check_number (lua_State *L, int narg) { 89LUA_API double luaL_check_number (lua_State *L, int narg) {
90 double d = lua_tonumber(L, narg); 90 double d = lua_tonumber(L, narg);
91 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */ 91 if (d == 0 && !lua_isnumber(L, narg)) /* avoid extra test when d is not 0 */
92 type_error(L, narg, LUA_TNUMBER); 92 type_error(L, narg, LUA_TNUMBER);
@@ -94,20 +94,20 @@ double luaL_check_number (lua_State *L, int narg) {
94} 94}
95 95
96 96
97double luaL_opt_number (lua_State *L, int narg, double def) { 97LUA_API double luaL_opt_number (lua_State *L, int narg, double def) {
98 if (lua_isnull(L, narg)) return def; 98 if (lua_isnull(L, narg)) return def;
99 else return luaL_check_number(L, narg); 99 else return luaL_check_number(L, narg);
100} 100}
101 101
102 102
103void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) { 103LUA_API void luaL_openlib (lua_State *L, const struct luaL_reg *l, int n) {
104 int i; 104 int i;
105 for (i=0; i<n; i++) 105 for (i=0; i<n; i++)
106 lua_register(L, l[i].name, l[i].func); 106 lua_register(L, l[i].name, l[i].func);
107} 107}
108 108
109 109
110void luaL_verror (lua_State *L, const char *fmt, ...) { 110LUA_API void luaL_verror (lua_State *L, const char *fmt, ...) {
111 char buff[500]; 111 char buff[500];
112 va_list argp; 112 va_list argp;
113 va_start(argp, fmt); 113 va_start(argp, fmt);
@@ -164,25 +164,25 @@ static void adjuststack (luaL_Buffer *B) {
164} 164}
165 165
166 166
167char *luaL_prepbuffer (luaL_Buffer *B) { 167LUA_API char *luaL_prepbuffer (luaL_Buffer *B) {
168 if (emptybuffer(B)) 168 if (emptybuffer(B))
169 adjuststack(B); 169 adjuststack(B);
170 return B->buffer; 170 return B->buffer;
171} 171}
172 172
173 173
174void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { 174LUA_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
175 while (l--) 175 while (l--)
176 luaL_putchar(B, *s++); 176 luaL_putchar(B, *s++);
177} 177}
178 178
179 179
180void luaL_addstring (luaL_Buffer *B, const char *s) { 180LUA_API void luaL_addstring (luaL_Buffer *B, const char *s) {
181 luaL_addlstring(B, s, strlen(s)); 181 luaL_addlstring(B, s, strlen(s));
182} 182}
183 183
184 184
185void luaL_pushresult (luaL_Buffer *B) { 185LUA_API void luaL_pushresult (luaL_Buffer *B) {
186 emptybuffer(B); 186 emptybuffer(B);
187 if (B->level == 0) 187 if (B->level == 0)
188 lua_pushlstring(B->L, NULL, 0); 188 lua_pushlstring(B->L, NULL, 0);
@@ -192,7 +192,7 @@ void luaL_pushresult (luaL_Buffer *B) {
192} 192}
193 193
194 194
195void luaL_addvalue (luaL_Buffer *B) { 195LUA_API void luaL_addvalue (luaL_Buffer *B) {
196 lua_State *L = B->L; 196 lua_State *L = B->L;
197 size_t vl = lua_strlen(L, -1); 197 size_t vl = lua_strlen(L, -1);
198 if (vl <= bufffree(B)) { /* fit into buffer? */ 198 if (vl <= bufffree(B)) { /* fit into buffer? */
@@ -209,7 +209,7 @@ void luaL_addvalue (luaL_Buffer *B) {
209} 209}
210 210
211 211
212void luaL_buffinit (lua_State *L, luaL_Buffer *B) { 212LUA_API void luaL_buffinit (lua_State *L, luaL_Buffer *B) {
213 B->L = L; 213 B->L = L;
214 B->p = B->buffer; 214 B->p = B->buffer;
215 B->level = 0; 215 B->level = 0;