Beispiel #1
0
static Proto* load(const char* filename)
{
 Proto* tf;
 ZIO z;
 char source[512];
 FILE* f;
 int c,undump;
 if (filename==NULL) 
 {
  f=stdin;
  filename="(stdin)";
 }
 else
  f=efopen(filename,"r");
 c=ungetc(fgetc(f),f);
 if (ferror(f))
 {
  fprintf(stderr,"luac: cannot read from ");
  perror(filename);
  exit(1);
 }
 undump=(c==ID_CHUNK);
 if (undump && f!=stdin)
 {
  fclose(f);
  f=efopen(filename,"rb");
 }
 sprintf(source,"@%.*s",Sizeof(source)-2,filename);
 luaZ_Fopen(&z,f,source);
 tf = undump ? luaU_undump(L,&z) : luaY_parser(L,&z);
 if (f!=stdin) fclose(f);
 return tf;
}
Beispiel #2
0
/*
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
*/
static int protectedparser (ZIO *z, int bin) {
  volatile struct C_Lua_Stack oldCLS = L->Cstack;
  struct lua_longjmp myErrorJmp;
  volatile int status;
  TProtoFunc *volatile tf;
  struct lua_longjmp *volatile oldErr = L->errorJmp;
  L->errorJmp = &myErrorJmp;
  if (setjmp(myErrorJmp.b) == 0) {
    tf = bin ? luaU_undump1(z) : luaY_parser(z);
    status = 0;
  }
  else {  /* an error occurred: restore L->Cstack and L->stack.top */
    L->Cstack = oldCLS;
    L->stack.top = L->stack.stack+L->Cstack.base;
    tf = NULL;
    status = 1;
  }
  L->errorJmp = oldErr;
  if (status) return 1;  /* error code */
  if (tf == NULL) return 2;  /* 'natural' end */
  luaD_adjusttop(L->Cstack.base+1);  /* one slot for the pseudo-function */
  L->stack.stack[L->Cstack.base].ttype = LUA_T_PROTO;
  L->stack.stack[L->Cstack.base].value.tf = tf;
  luaV_closure(0);
  return 0;
}
Beispiel #3
0
int terra_load(lua_State *L,lua_Reader reader, void *data, const char *chunkname) {
    int st = lua_gettop(L);
    terra_State * T = getterra(L);
    Zio zio;
    luaZ_init(T,&zio,reader,data);
    int r = luaY_parser(T,&zio,chunkname,zgetc(&zio));
    assert(lua_gettop(L) == st + 1);
    return r;
}
Beispiel #4
0
static void do_compile(ZIO* z)
{
 TProtoFunc* Main;
 if (optimizing) L->debug=0;
 if (debugging)  L->debug=1;
 Main=luaY_parser(z);
 if (optimizing) luaU_optchunk(Main);
 if (listing) luaU_printchunk(Main);
 if (testing) luaU_testchunk(Main);
 if (dumping) luaU_dumpchunk(Main,D,native);
}
Beispiel #5
0
static Proto* load(const char* filename)
{
	Proto* tf;
	ZIO z;
	char source[512];
	PHYSFS_file* f;


        /* Open the file */
	f = efopen(filename, "r");

	sprintf(source,"@%.*s",Sizeof(source)-2,filename);

	luaZ_Fopen(&z,f,source);

        /* Parse the lua code */
	tf = luaY_parser(compile_lua_state,&z);

        /* Close the file */
	my_fclose(f);

	return tf;
}
Beispiel #6
0
/*
** returns 0 = chunk loaded; 1 = error; 2 = no more chunks to load
*/
static int32 protectedparser(ZIO *z, int32 bin) {
	int32 status;
	TProtoFunc *tf;
	jmp_buf myErrorJmp;
	jmp_buf *oldErr = lua_state->errorJmp;
	lua_state->errorJmp = &myErrorJmp;
	if (setjmp(myErrorJmp) == 0) {
		tf = bin ? luaU_undump1(z) : luaY_parser(z);
		status = 0;
	} else {
		tf = NULL;
		status = 1;
	}
	lua_state->errorJmp = oldErr;
	if (status)
		return 1;  // error code
	if (tf == NULL)
		return 2;  // 'natural' end
	luaD_adjusttop(lua_state->Cstack.base + 1);  // one slot for the pseudo-function
	lua_state->stack.stack[lua_state->Cstack.base].ttype = LUA_T_PROTO;
	lua_state->stack.stack[lua_state->Cstack.base].value.tf = tf;
	luaV_closure(0);
	return 0;
}
Beispiel #7
0
Datei: ldo.c Projekt: jcubic/ToME
static void f_parser (lua_State *L, void *ud) {
  struct ParserS *p = (struct ParserS *)ud;
  Proto *tf = p->bin ? luaU_undump(L, p->z) : luaY_parser(L, p->z);
  luaV_Lclosure(L, tf, 0);
}
Beispiel #8
0
Datei: luac.c Projekt: jeske/hz
static void do_compile(ZIO* z)
{
    TProtoFunc* Main=luaY_parser(z);
    if (listing) PrintChunk(Main);
    if (dumping) DumpChunk(Main,D);
}