aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-02-23 14:17:25 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-02-23 14:17:25 -0300
commit39b79783297bee79db9853b63d199e120a009a8f (patch)
treec738c621c4c28d8822c2f785400786301985273b /ldo.c
parentd164e2294f73d8e69f00d95a66014514b2dd0ec0 (diff)
downloadlua-39b79783297bee79db9853b63d199e120a009a8f.tar.gz
lua-39b79783297bee79db9853b63d199e120a009a8f.tar.bz2
lua-39b79783297bee79db9853b63d199e120a009a8f.zip
first (big) step to support wide chars
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c44
1 files changed, 22 insertions, 22 deletions
diff --git a/ldo.c b/ldo.c
index 30c0c241..84a2c985 100644
--- a/ldo.c
+++ b/ldo.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldo.c,v 1.126 2001/02/22 18:59:59 roberto Exp roberto $ 2** $Id: ldo.c,v 1.127 2001/02/23 13:38:56 roberto Exp roberto $
3** Stack and Call structure of Lua 3** Stack and Call structure of Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -56,7 +56,7 @@ void luaD_checkstack (lua_State *L, int n) {
56 else { 56 else {
57 L->stack_last += EXTRA_STACK; /* to be used by error message */ 57 L->stack_last += EXTRA_STACK; /* to be used by error message */
58 lua_assert(L->stack_last == L->stack+L->stacksize-1); 58 lua_assert(L->stack_last == L->stack+L->stacksize-1);
59 luaD_error(L, "stack overflow"); 59 luaD_error(L, l_s("stack overflow"));
60 } 60 }
61 } 61 }
62} 62}
@@ -108,7 +108,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) {
108 if (L->allowhooks) { 108 if (L->allowhooks) {
109 lua_Debug ar; 109 lua_Debug ar;
110 ar._func = func; 110 ar._func = func;
111 ar.event = "line"; 111 ar.event = l_s("line");
112 ar.currentline = line; 112 ar.currentline = line;
113 dohook(L, &ar, linehook); 113 dohook(L, &ar, linehook);
114 } 114 }
@@ -116,7 +116,7 @@ void luaD_lineHook (lua_State *L, StkId func, int line, lua_Hook linehook) {
116 116
117 117
118static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook, 118static void luaD_callHook (lua_State *L, StkId func, lua_Hook callhook,
119 const char *event) { 119 const l_char *event) {
120 if (L->allowhooks) { 120 if (L->allowhooks) {
121 lua_Debug ar; 121 lua_Debug ar;
122 ar._func = func; 122 ar._func = func;
@@ -159,7 +159,7 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
159 /* `func' is not a function; check the `function' tag method */ 159 /* `func' is not a function; check the `function' tag method */
160 Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION); 160 Closure *tm = luaT_gettmbyObj(G(L), func, TM_FUNCTION);
161 if (tm == NULL) 161 if (tm == NULL)
162 luaG_typeerror(L, func, "call"); 162 luaG_typeerror(L, func, l_s("call"));
163 luaD_openstack(L, func); 163 luaD_openstack(L, func);
164 setclvalue(func, tm); /* tag method is the new function to be called */ 164 setclvalue(func, tm); /* tag method is the new function to be called */
165 } 165 }
@@ -168,11 +168,11 @@ void luaD_call (lua_State *L, StkId func, int nResults) {
168 setivalue(func, &ci); 168 setivalue(func, &ci);
169 callhook = L->callhook; 169 callhook = L->callhook;
170 if (callhook) 170 if (callhook)
171 luaD_callHook(L, func, callhook, "call"); 171 luaD_callHook(L, func, callhook, l_s("call"));
172 firstResult = (cl->isC ? callCclosure(L, cl, func+1) : 172 firstResult = (cl->isC ? callCclosure(L, cl, func+1) :
173 luaV_execute(L, cl, func+1)); 173 luaV_execute(L, cl, func+1));
174 if (callhook) /* same hook that was active at entry */ 174 if (callhook) /* same hook that was active at entry */
175 luaD_callHook(L, func, callhook, "return"); 175 luaD_callHook(L, func, callhook, l_s("return"));
176 lua_assert(ttype(func) == LUA_TMARK); 176 lua_assert(ttype(func) == LUA_TMARK);
177 setnilvalue(func); /* remove callinfo from the stack */ 177 setnilvalue(func); /* remove callinfo from the stack */
178 /* move results to `func' (to erase parameters and function) */ 178 /* move results to `func' (to erase parameters and function) */
@@ -261,20 +261,20 @@ static int protectedparser (lua_State *L, ZIO *z, int bin) {
261} 261}
262 262
263 263
264static int parse_file (lua_State *L, const char *filename) { 264static int parse_file (lua_State *L, const l_char *filename) {
265 ZIO z; 265 ZIO z;
266 int status; 266 int status;
267 int bin; /* flag for file mode */ 267 int bin; /* flag for file mode */
268 FILE *f = (filename == NULL) ? stdin : fopen(filename, "r"); 268 FILE *f = (filename == NULL) ? stdin : fopen(filename, l_s("r"));
269 if (f == NULL) return LUA_ERRFILE; /* unable to open file */ 269 if (f == NULL) return LUA_ERRFILE; /* unable to open file */
270 bin = (ungetc(fgetc(f), f) == ID_CHUNK); 270 bin = (ungetc(fgetc(f), f) == ID_CHUNK);
271 if (bin && f != stdin) { 271 if (bin && f != stdin) {
272 fclose(f); 272 fclose(f);
273 f = fopen(filename, "rb"); /* reopen in binary mode */ 273 f = fopen(filename, l_s("rb")); /* reopen in binary mode */
274 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */ 274 if (f == NULL) return LUA_ERRFILE; /* unable to reopen file */
275 } 275 }
276 lua_pushliteral(L, "@"); 276 lua_pushliteral(L, l_s("@"));
277 lua_pushstring(L, (filename == NULL) ? "(stdin)" : filename); 277 lua_pushstring(L, (filename == NULL) ? l_s("(stdin)") : filename);
278 lua_concat(L, 2); 278 lua_concat(L, 2);
279 filename = lua_tostring(L, -1); /* filename = `@'..filename */ 279 filename = lua_tostring(L, -1); /* filename = `@'..filename */
280 luaZ_Fopen(&z, f, filename); 280 luaZ_Fopen(&z, f, filename);
@@ -286,7 +286,7 @@ static int parse_file (lua_State *L, const char *filename) {
286} 286}
287 287
288 288
289LUA_API int lua_dofile (lua_State *L, const char *filename) { 289LUA_API int lua_dofile (lua_State *L, const l_char *filename) {
290 int status; 290 int status;
291 status = parse_file(L, filename); 291 status = parse_file(L, filename);
292 if (status == 0) /* parse OK? */ 292 if (status == 0) /* parse OK? */
@@ -295,18 +295,18 @@ LUA_API int lua_dofile (lua_State *L, const char *filename) {
295} 295}
296 296
297 297
298static int parse_buffer (lua_State *L, const char *buff, size_t size, 298static int parse_buffer (lua_State *L, const l_char *buff, size_t size,
299 const char *name) { 299 const l_char *name) {
300 ZIO z; 300 ZIO z;
301 int status; 301 int status;
302 if (!name) name = "?"; 302 if (!name) name = l_s("?");
303 luaZ_mopen(&z, buff, size, name); 303 luaZ_mopen(&z, buff, size, name);
304 status = protectedparser(L, &z, buff[0]==ID_CHUNK); 304 status = protectedparser(L, &z, buff[0]==ID_CHUNK);
305 return status; 305 return status;
306} 306}
307 307
308 308
309LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const char *name) { 309LUA_API int lua_dobuffer (lua_State *L, const l_char *buff, size_t size, const l_char *name) {
310 int status; 310 int status;
311 status = parse_buffer(L, buff, size, name); 311 status = parse_buffer(L, buff, size, name);
312 if (status == 0) /* parse OK? */ 312 if (status == 0) /* parse OK? */
@@ -315,7 +315,7 @@ LUA_API int lua_dobuffer (lua_State *L, const char *buff, size_t size, const cha
315} 315}
316 316
317 317
318LUA_API int lua_dostring (lua_State *L, const char *str) { 318LUA_API int lua_dostring (lua_State *L, const l_char *str) {
319 return lua_dobuffer(L, str, strlen(str), str); 319 return lua_dobuffer(L, str, strlen(str), str);
320} 320}
321 321
@@ -334,8 +334,8 @@ struct lua_longjmp {
334}; 334};
335 335
336 336
337static void message (lua_State *L, const char *s) { 337static void message (lua_State *L, const l_char *s) {
338 luaV_getglobal(L, luaS_newliteral(L, LUA_ERRORMESSAGE), L->top); 338 luaV_getglobal(L, luaS_newliteral(L, l_s(LUA_ERRORMESSAGE)), L->top);
339 if (ttype(L->top) == LUA_TFUNCTION) { 339 if (ttype(L->top) == LUA_TFUNCTION) {
340 incr_top; 340 incr_top;
341 setsvalue(L->top, luaS_new(L, s)); 341 setsvalue(L->top, luaS_new(L, s));
@@ -348,7 +348,7 @@ static void message (lua_State *L, const char *s) {
348/* 348/*
349** Reports an error, and jumps up to the available recovery label 349** Reports an error, and jumps up to the available recovery label
350*/ 350*/
351void luaD_error (lua_State *L, const char *s) { 351void luaD_error (lua_State *L, const l_char *s) {
352 if (s) message(L, s); 352 if (s) message(L, s);
353 luaD_breakrun(L, LUA_ERRRUN); 353 luaD_breakrun(L, LUA_ERRRUN);
354} 354}
@@ -361,7 +361,7 @@ void luaD_breakrun (lua_State *L, int errcode) {
361 } 361 }
362 else { 362 else {
363 if (errcode != LUA_ERRMEM) 363 if (errcode != LUA_ERRMEM)
364 message(L, "unable to recover; exiting\n"); 364 message(L, l_s("unable to recover; exiting\n"));
365 exit(EXIT_FAILURE); 365 exit(EXIT_FAILURE);
366 } 366 }
367} 367}