diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-03-06 13:54:42 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1998-03-06 13:54:42 -0300 |
commit | 88a2023c3285c4514519158fba90e644fc6ffca3 (patch) | |
tree | da6611257545c486ff856dd48d66d94e056f3d66 /lapi.c | |
parent | 5ef1989c4b05aff8362a7ea6ba62aad76d4a040d (diff) | |
download | lua-88a2023c3285c4514519158fba90e644fc6ffca3.tar.gz lua-88a2023c3285c4514519158fba90e644fc6ffca3.tar.bz2 lua-88a2023c3285c4514519158fba90e644fc6ffca3.zip |
support for strings with '\0'
Diffstat (limited to 'lapi.c')
-rw-r--r-- | lapi.c | 30 |
1 files changed, 21 insertions, 9 deletions
@@ -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) | |||
219 | lua_Object lua_rawgetglobal (char *name) | 219 | lua_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 | ||
296 | long 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 | |||
296 | void *lua_getuserdata (lua_Object object) | 304 | void *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 | ||
324 | void lua_pushstring (char *s) | 332 | void 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 | ||
340 | void lua_pushstring (char *s) | ||
341 | { | ||
342 | if (s == NULL) | ||
343 | lua_pushnil(); | ||
344 | else | ||
345 | lua_pushlstr(s, strlen(s)); | ||
346 | } | ||
347 | |||
336 | void lua_pushCclosure (lua_CFunction fn, int n) | 348 | void lua_pushCclosure (lua_CFunction fn, int n) |
337 | { | 349 | { |
338 | if (fn == NULL) | 350 | if (fn == NULL) |