summaryrefslogtreecommitdiff
path: root/opcode.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-16 13:50:22 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1997-06-16 13:50:22 -0300
commitc9a2dfeb2c71b1c6b8164a1e5aad4b178950e197 (patch)
tree6f099e983ecb968f625a8824ac2ca78e625882e3 /opcode.c
parent9fe5be3acf340b90fe0c24d36a601adaf6f21c79 (diff)
downloadlua-c9a2dfeb2c71b1c6b8164a1e5aad4b178950e197.tar.gz
lua-c9a2dfeb2c71b1c6b8164a1e5aad4b178950e197.tar.bz2
lua-c9a2dfeb2c71b1c6b8164a1e5aad4b178950e197.zip
using "zio" for parsing Lua code.
Diffstat (limited to 'opcode.c')
-rw-r--r--opcode.c52
1 files changed, 5 insertions, 47 deletions
diff --git a/opcode.c b/opcode.c
index 84b69c80..04a5b5ab 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 4.7 1997/06/09 17:28:14 roberto Exp roberto $"; 6char *rcs_opcode="$Id: opcode.c,v 4.8 1997/06/12 18:27:29 roberto Exp roberto $";
7 7
8#include <setjmp.h> 8#include <setjmp.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -18,8 +18,8 @@ char *rcs_opcode="$Id: opcode.c,v 4.7 1997/06/09 17:28:14 roberto Exp roberto $"
18#include "table.h" 18#include "table.h"
19#include "lua.h" 19#include "lua.h"
20#include "fallback.h" 20#include "fallback.h"
21#include "undump.h"
22#include "auxlib.h" 21#include "auxlib.h"
22#include "lex.h"
23 23
24#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0)) 24#define tonumber(o) ((ttype(o) != LUA_T_NUMBER) && (lua_tonumber(o) != 0))
25#define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0)) 25#define tostring(o) ((ttype(o) != LUA_T_STRING) && (lua_tostring(o) != 0))
@@ -597,7 +597,8 @@ int luaI_dorun (TFunc *tf)
597 return status; 597 return status;
598} 598}
599 599
600static int do_protectedmain (lua_CFunction closef) 600
601int lua_domain (void)
601{ 602{
602 TFunc tf; 603 TFunc tf;
603 int status; 604 int status;
@@ -614,7 +615,6 @@ static int do_protectedmain (lua_CFunction closef)
614 adjustC(0); /* erase extra slot */ 615 adjustC(0); /* erase extra slot */
615 status = 1; 616 status = 1;
616 } 617 }
617 closef();
618 if (status == 0) 618 if (status == 0)
619 status = luaI_dorun(&tf); 619 status = luaI_dorun(&tf);
620 errorJmp = oldErr; 620 errorJmp = oldErr;
@@ -622,7 +622,6 @@ static int do_protectedmain (lua_CFunction closef)
622 return status; 622 return status;
623} 623}
624 624
625
626/* 625/*
627** Execute the given lua function. Return 0 on success or 1 on error. 626** Execute the given lua function. Return 0 on success or 1 on error.
628*/ 627*/
@@ -640,47 +639,6 @@ int lua_callfunction (lua_Object function)
640 639
641 640
642/* 641/*
643** Open file, generate opcode and execute global statement. Return 0 on
644** success or non 0 on error.
645*/
646int lua_dofile (char *filename)
647{
648 int status;
649 int c;
650 FILE *f = lua_openfile(filename);
651 if (f == NULL)
652 return 2;
653 c = fgetc(f);
654 ungetc(c, f);
655 if (c == ID_CHUNK) {
656 f = freopen(filename, "rb", f); /* set binary mode */
657 status = luaI_undump(f);
658 lua_closefile();
659 }
660 else {
661 if (c == '#')
662 while ((c=fgetc(f)) != '\n') /* skip first line */;
663 status = do_protectedmain(lua_closefile);
664 }
665 return status;
666}
667
668/*
669** Generate opcode stored on string and execute global statement. Return 0 on
670** success or non 0 on error.
671*/
672int lua_dostring (char *str)
673{
674 int status;
675 if (str == NULL)
676 return 1;
677 lua_openstring(str);
678 status = do_protectedmain(lua_closestring);
679 return status;
680}
681
682
683/*
684** API: set a function as a fallback 642** API: set a function as a fallback
685*/ 643*/
686lua_Object lua_setfallback (char *name, lua_CFunction fallback) 644lua_Object lua_setfallback (char *name, lua_CFunction fallback)
@@ -1058,7 +1016,7 @@ static void call_arith (IMS event)
1058 if (ttype(im) == LUA_T_NIL) { 1016 if (ttype(im) == LUA_T_NIL) {
1059 im = luaI_getim(0, event); /* try a 'global' i.m. */ 1017 im = luaI_getim(0, event); /* try a 'global' i.m. */
1060 if (ttype(im) == LUA_T_NIL) 1018 if (ttype(im) == LUA_T_NIL)
1061 lua_error("unexpected type at conversion to number"); 1019 lua_error("unexpected type at arithmetic operation");
1062 } 1020 }
1063 } 1021 }
1064 lua_pushstring(luaI_eventname[event]); 1022 lua_pushstring(luaI_eventname[event]);