aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-03-06 13:54:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1998-03-06 13:54:42 -0300
commit88a2023c3285c4514519158fba90e644fc6ffca3 (patch)
treeda6611257545c486ff856dd48d66d94e056f3d66 /lapi.c
parent5ef1989c4b05aff8362a7ea6ba62aad76d4a040d (diff)
downloadlua-88a2023c3285c4514519158fba90e644fc6ffca3.tar.gz
lua-88a2023c3285c4514519158fba90e644fc6ffca3.tar.bz2
lua-88a2023c3285c4514519158fba90e644fc6ffca3.zip
support for strings with '\0'
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/lapi.c b/lapi.c
index 8528dd65..5f1a81ba 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 1.20 1998/01/27 19:13:45 roberto Exp roberto $ 2** $Id: lapi.c,v 1.21 1998/02/12 19:23:32 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -219,7 +219,7 @@ lua_Object lua_getglobal (char *name)
219lua_Object lua_rawgetglobal (char *name) 219lua_Object lua_rawgetglobal (char *name)
220{ 220{
221 TaggedString *ts = luaS_new(name); 221 TaggedString *ts = luaS_new(name);
222 return put_luaObject(&ts->u.globalval); 222 return put_luaObject(&ts->u.s.globalval);
223} 223}
224 224
225 225
@@ -293,6 +293,14 @@ char *lua_getstring (lua_Object object)
293 else return (svalue(Address(object))); 293 else return (svalue(Address(object)));
294} 294}
295 295
296long lua_getstrlen (lua_Object object)
297{
298 luaC_checkGC(); /* "tostring" may create a new string */
299 if (object == LUA_NOOBJECT || tostring(Address(object)))
300 return 0L;
301 else return (tsvalue(Address(object))->u.s.len);
302}
303
296void *lua_getuserdata (lua_Object object) 304void *lua_getuserdata (lua_Object object)
297{ 305{
298 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA) 306 if (object == LUA_NOOBJECT || ttype(Address(object)) != LUA_T_USERDATA)
@@ -321,18 +329,22 @@ void lua_pushnumber (double n)
321 incr_top; 329 incr_top;
322} 330}
323 331
324void lua_pushstring (char *s) 332void lua_pushlstr (char *s, long len)
325{ 333{
326 if (s == NULL) 334 tsvalue(L->stack.top) = luaS_newlstr(s, len);
327 ttype(L->stack.top) = LUA_T_NIL; 335 ttype(L->stack.top) = LUA_T_STRING;
328 else {
329 tsvalue(L->stack.top) = luaS_new(s);
330 ttype(L->stack.top) = LUA_T_STRING;
331 }
332 incr_top; 336 incr_top;
333 luaC_checkGC(); 337 luaC_checkGC();
334} 338}
335 339
340void lua_pushstring (char *s)
341{
342 if (s == NULL)
343 lua_pushnil();
344 else
345 lua_pushlstr(s, strlen(s));
346}
347
336void lua_pushCclosure (lua_CFunction fn, int n) 348void lua_pushCclosure (lua_CFunction fn, int n)
337{ 349{
338 if (fn == NULL) 350 if (fn == NULL)