From 5dfd17dd769d159a3b0722ddf82b385ff7271d53 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 13 Dec 1994 13:54:21 -0200 Subject: new API function 'lua_pushliteral' --- inout.c | 16 ++++++++-------- lua.h | 14 +++++++++----- opcode.c | 15 ++++++++++++++- strlib.c | 4 ++-- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/inout.c b/inout.c index 31859a82..0f879d60 100644 --- a/inout.c +++ b/inout.c @@ -5,7 +5,7 @@ ** Also provides some predefined lua functions. */ -char *rcs_inout="$Id: inout.c,v 2.12 1994/11/21 21:41:09 roberto Exp $"; +char *rcs_inout="$Id: inout.c,v 2.13 1994/11/23 14:32:00 roberto Stab $"; #include #include @@ -240,25 +240,25 @@ void luaI_type (void) switch (lua_type(o)) { case LUA_T_NIL : - lua_pushstring("nil"); + lua_pushliteral("nil"); break; case LUA_T_NUMBER : - lua_pushstring("number"); + lua_pushliteral("number"); break; case LUA_T_STRING : - lua_pushstring("string"); + lua_pushliteral("string"); break; case LUA_T_ARRAY : - lua_pushstring("table"); + lua_pushliteral("table"); break; case LUA_T_FUNCTION : - lua_pushstring("function"); + lua_pushliteral("function"); break; case LUA_T_CFUNCTION : - lua_pushstring("cfunction"); + lua_pushliteral("cfunction"); break; default : - lua_pushstring("userdata"); + lua_pushliteral("userdata"); break; } } diff --git a/lua.h b/lua.h index 221060eb..6fe7aca0 100644 --- a/lua.h +++ b/lua.h @@ -2,7 +2,7 @@ ** LUA - Linguagem para Usuarios de Aplicacao ** Grupo de Tecnologia em Computacao Grafica ** TeCGraf - PUC-Rio -** $Id: lua.h,v 3.10 1994/11/17 21:27:30 roberto Exp roberto $ +** $Id: lua.h,v 3.11 1994/11/18 19:46:21 roberto Stab roberto $ */ @@ -51,6 +51,7 @@ void *lua_getuserdata (lua_Object object); int lua_pushnil (void); int lua_pushnumber (float n); int lua_pushstring (char *s); +int lua_pushliteral (char *s); int lua_pushcfunction (lua_CFunction fn); int lua_pushusertag (void *u, int tag); int lua_pushobject (lua_Object object); @@ -70,15 +71,12 @@ void lua_unlock (int ref); lua_Object lua_createtable (int initSize); -/* for lua 1.1 */ +/* some useful macros */ #define lua_lockobject(o) (lua_pushobject(o), lua_lock()) #define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) -#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) -#define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) - #define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA) #define lua_isnil(_) (lua_type(_)==LUA_T_NIL) @@ -89,4 +87,10 @@ lua_Object lua_createtable (int initSize); #define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION) #define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA) + +/* for lua 1.1 compatibility. Avoid using these macros */ + +#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript()) +#define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript()) + #endif diff --git a/opcode.c b/opcode.c index 64dcca68..437a1da5 100644 --- a/opcode.c +++ b/opcode.c @@ -3,7 +3,7 @@ ** TecCGraf - PUC-Rio */ -char *rcs_opcode="$Id: opcode.c,v 3.23 1994/11/30 21:20:37 roberto Exp roberto $"; +char *rcs_opcode="$Id: opcode.c,v 3.24 1994/12/06 14:27:18 roberto Exp roberto $"; #include #include @@ -643,6 +643,19 @@ int lua_pushstring (char *s) return 0; } +/* +** Push an object (tag=string) on stack and register it on the constant table. + Return 0 on success or 1 on error. +*/ +int lua_pushliteral (char *s) +{ + lua_checkstack(top-stack+1); + tsvalue(top) = lua_constant[luaI_findconstant(lua_constcreate(s))]; + tag(top) = LUA_T_STRING; + top++; + return 0; +} + /* ** Push an object (tag=cfunction) to stack. Return 0 on success or 1 on error. */ diff --git a/strlib.c b/strlib.c index a5d44da9..ef79ac82 100644 --- a/strlib.c +++ b/strlib.c @@ -3,7 +3,7 @@ ** String library to LUA */ -char *rcs_strlib="$Id: strlib.c,v 1.4 1994/10/18 18:34:47 roberto Exp roberto $"; +char *rcs_strlib="$Id: strlib.c,v 1.5 1994/11/16 17:38:08 roberto Stab $"; #include #include @@ -67,7 +67,7 @@ static void str_sub (void) start = lua_getnumber (o2); end = o3 == NULL ? strlen(s) : lua_getnumber (o3); if (end < start || start < 1 || end > strlen(s)) - lua_pushstring(""); + lua_pushliteral(""); else { s[end] = 0; -- cgit v1.2.3-55-g6feb