aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-12-13 13:54:21 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-12-13 13:54:21 -0200
commit5dfd17dd769d159a3b0722ddf82b385ff7271d53 (patch)
tree5e4329c717d7276191c711a80ea9323bf0560a4c
parentce4fb88b34421bc4426db7985314ba7ed757a284 (diff)
downloadlua-5dfd17dd769d159a3b0722ddf82b385ff7271d53.tar.gz
lua-5dfd17dd769d159a3b0722ddf82b385ff7271d53.tar.bz2
lua-5dfd17dd769d159a3b0722ddf82b385ff7271d53.zip
new API function 'lua_pushliteral'
-rw-r--r--inout.c16
-rw-r--r--lua.h14
-rw-r--r--opcode.c15
-rw-r--r--strlib.c4
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 @@
5** Also provides some predefined lua functions. 5** Also provides some predefined lua functions.
6*/ 6*/
7 7
8char *rcs_inout="$Id: inout.c,v 2.12 1994/11/21 21:41:09 roberto Exp $"; 8char *rcs_inout="$Id: inout.c,v 2.13 1994/11/23 14:32:00 roberto Stab $";
9 9
10#include <stdio.h> 10#include <stdio.h>
11#include <stdlib.h> 11#include <stdlib.h>
@@ -240,25 +240,25 @@ void luaI_type (void)
240 switch (lua_type(o)) 240 switch (lua_type(o))
241 { 241 {
242 case LUA_T_NIL : 242 case LUA_T_NIL :
243 lua_pushstring("nil"); 243 lua_pushliteral("nil");
244 break; 244 break;
245 case LUA_T_NUMBER : 245 case LUA_T_NUMBER :
246 lua_pushstring("number"); 246 lua_pushliteral("number");
247 break; 247 break;
248 case LUA_T_STRING : 248 case LUA_T_STRING :
249 lua_pushstring("string"); 249 lua_pushliteral("string");
250 break; 250 break;
251 case LUA_T_ARRAY : 251 case LUA_T_ARRAY :
252 lua_pushstring("table"); 252 lua_pushliteral("table");
253 break; 253 break;
254 case LUA_T_FUNCTION : 254 case LUA_T_FUNCTION :
255 lua_pushstring("function"); 255 lua_pushliteral("function");
256 break; 256 break;
257 case LUA_T_CFUNCTION : 257 case LUA_T_CFUNCTION :
258 lua_pushstring("cfunction"); 258 lua_pushliteral("cfunction");
259 break; 259 break;
260 default : 260 default :
261 lua_pushstring("userdata"); 261 lua_pushliteral("userdata");
262 break; 262 break;
263 } 263 }
264} 264}
diff --git a/lua.h b/lua.h
index 221060eb..6fe7aca0 100644
--- a/lua.h
+++ b/lua.h
@@ -2,7 +2,7 @@
2** LUA - Linguagem para Usuarios de Aplicacao 2** LUA - Linguagem para Usuarios de Aplicacao
3** Grupo de Tecnologia em Computacao Grafica 3** Grupo de Tecnologia em Computacao Grafica
4** TeCGraf - PUC-Rio 4** TeCGraf - PUC-Rio
5** $Id: lua.h,v 3.10 1994/11/17 21:27:30 roberto Exp roberto $ 5** $Id: lua.h,v 3.11 1994/11/18 19:46:21 roberto Stab roberto $
6*/ 6*/
7 7
8 8
@@ -51,6 +51,7 @@ void *lua_getuserdata (lua_Object object);
51int lua_pushnil (void); 51int lua_pushnil (void);
52int lua_pushnumber (float n); 52int lua_pushnumber (float n);
53int lua_pushstring (char *s); 53int lua_pushstring (char *s);
54int lua_pushliteral (char *s);
54int lua_pushcfunction (lua_CFunction fn); 55int lua_pushcfunction (lua_CFunction fn);
55int lua_pushusertag (void *u, int tag); 56int lua_pushusertag (void *u, int tag);
56int lua_pushobject (lua_Object object); 57int lua_pushobject (lua_Object object);
@@ -70,15 +71,12 @@ void lua_unlock (int ref);
70lua_Object lua_createtable (int initSize); 71lua_Object lua_createtable (int initSize);
71 72
72 73
73/* for lua 1.1 */ 74/* some useful macros */
74 75
75#define lua_lockobject(o) (lua_pushobject(o), lua_lock()) 76#define lua_lockobject(o) (lua_pushobject(o), lua_lock())
76 77
77#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n)) 78#define lua_register(n,f) (lua_pushcfunction(f), lua_storeglobal(n))
78 79
79#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
80#define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript())
81
82#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA) 80#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA)
83 81
84#define lua_isnil(_) (lua_type(_)==LUA_T_NIL) 82#define lua_isnil(_) (lua_type(_)==LUA_T_NIL)
@@ -89,4 +87,10 @@ lua_Object lua_createtable (int initSize);
89#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION) 87#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION)
90#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA) 88#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA)
91 89
90
91/* for lua 1.1 compatibility. Avoid using these macros */
92
93#define lua_getindexed(o,n) (lua_pushobject(o), lua_pushnumber(n), lua_getsubscript())
94#define lua_getfield(o,f) (lua_pushobject(o), lua_pushstring(f), lua_getsubscript())
95
92#endif 96#endif
diff --git a/opcode.c b/opcode.c
index 64dcca68..437a1da5 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.23 1994/11/30 21:20:37 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 3.24 1994/12/06 14:27:18 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -644,6 +644,19 @@ int lua_pushstring (char *s)
644} 644}
645 645
646/* 646/*
647** Push an object (tag=string) on stack and register it on the constant table.
648 Return 0 on success or 1 on error.
649*/
650int lua_pushliteral (char *s)
651{
652 lua_checkstack(top-stack+1);
653 tsvalue(top) = lua_constant[luaI_findconstant(lua_constcreate(s))];
654 tag(top) = LUA_T_STRING;
655 top++;
656 return 0;
657}
658
659/*
647** Push an object (tag=cfunction) to stack. Return 0 on success or 1 on error. 660** Push an object (tag=cfunction) to stack. Return 0 on success or 1 on error.
648*/ 661*/
649int lua_pushcfunction (lua_CFunction fn) 662int lua_pushcfunction (lua_CFunction fn)
diff --git a/strlib.c b/strlib.c
index a5d44da9..ef79ac82 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.4 1994/10/18 18:34:47 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.5 1994/11/16 17:38:08 roberto Stab $";
7 7
8#include <string.h> 8#include <string.h>
9#include <ctype.h> 9#include <ctype.h>
@@ -67,7 +67,7 @@ static void str_sub (void)
67 start = lua_getnumber (o2); 67 start = lua_getnumber (o2);
68 end = o3 == NULL ? strlen(s) : lua_getnumber (o3); 68 end = o3 == NULL ? strlen(s) : lua_getnumber (o3);
69 if (end < start || start < 1 || end > strlen(s)) 69 if (end < start || start < 1 || end > strlen(s))
70 lua_pushstring(""); 70 lua_pushliteral("");
71 else 71 else
72 { 72 {
73 s[end] = 0; 73 s[end] = 0;