novas funcoes 'gettable' e 'pushtable', nova implementacao do hash e

heranca nas indexacoes.
This commit is contained in:
Waldemar Celes 1994-08-17 12:02:03 -03:00
parent f490b1bff8
commit c4b8b1b989
1 changed files with 71 additions and 23 deletions

View File

@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio ** TecCGraf - PUC-Rio
*/ */
char *rcs_opcode="$Id: opcode.c,v 2.3 1994/08/03 14:15:46 celes Exp celes $"; char *rcs_opcode="$Id: opcode.c,v 2.4 1994/08/05 19:31:09 celes Exp celes $";
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -236,17 +236,10 @@ int lua_execute (Byte *pc)
break; break;
case PUSHINDEXED: case PUSHINDEXED:
--top; {
if (tag(top-1) != T_ARRAY) int s = lua_pushsubscript();
{ if (s == 1) return 1;
lua_reportbug ("indexed expression not a table"); }
return 1;
}
{
Object *h = lua_hashget (avalue(top-1), top);
if (h == NULL) return 1;
*(top-1) = *h;
}
break; break;
case PUSHMARK: tag(top++) = T_MARK; break; case PUSHMARK: tag(top++) = T_MARK; break;
@ -269,17 +262,10 @@ int lua_execute (Byte *pc)
break; break;
case STOREINDEXED0: case STOREINDEXED0:
if (tag(top-3) != T_ARRAY) {
{ int s = lua_storesubscript();
lua_reportbug ("indexed expression not a table"); if (s == 1) return 1;
return 1; }
}
{
Object *h = lua_hashdefine (avalue(top-3), top-2);
if (h == NULL) return 1;
*h = *(top-1);
}
top -= 3;
break; break;
case STOREINDEXED: case STOREINDEXED:
@ -640,6 +626,46 @@ int lua_execute (Byte *pc)
} }
/*
** Function to indexed the values on the top
*/
int lua_pushsubscript (void)
{
--top;
if (tag(top-1) != T_ARRAY)
{
lua_reportbug ("indexed expression not a table");
return 1;
}
{
Object *h = lua_hashget (avalue(top-1), top);
if (h == NULL) return 1;
*(top-1) = *h;
}
return 0;
}
/*
** Function to store indexed based on values at the top
*/
int lua_storesubscript (void)
{
if (tag(top-3) != T_ARRAY)
{
lua_reportbug ("indexed expression not a table");
return 1;
}
{
Object *h = lua_hashdefine (avalue(top-3), top-2);
if (h == NULL) return 1;
*h = *(top-1);
}
top -= 3;
return 0;
}
/* /*
** Traverse all objects on stack ** Traverse all objects on stack
*/ */
@ -767,6 +793,16 @@ void *lua_getuserdata (Object *object)
else return (uvalue(object)); else return (uvalue(object));
} }
/*
** Given an object handle, return its table. On error, return NULL.
*/
void *lua_gettable (Object *object)
{
if (object == NULL) return NULL;
if (tag(object) != T_ARRAY) return NULL;
else return (avalue(object));
}
/* /*
** Given an object handle and a field name, return its field object. ** Given an object handle and a field name, return its field object.
** On error, return NULL. ** On error, return NULL.
@ -879,6 +915,17 @@ int lua_pushuserdata (void *u)
return 0; return 0;
} }
/*
** Push an object (tag=userdata) to stack. Return 0 on success or 1 on error.
*/
int lua_pushtable (void *t)
{
if (lua_checkstack(top-stack+1) == 1)
return 1;
tag(top) = T_ARRAY; avalue(top++) = t;
return 0;
}
/* /*
** Push an object to stack. ** Push an object to stack.
*/ */
@ -903,6 +950,7 @@ int lua_storeglobal (char *name)
return 0; return 0;
} }
/* /*
** Store top of the stack at an array field. Return 1 on error, 0 on success. ** Store top of the stack at an array field. Return 1 on error, 0 on success.
*/ */