示例#1
0
文件: liolib.c 项目: gitrider/wxsj2
static int f_lines (lua_State *L) {
  tofile(L, 1);  /* check that it's a valid file handle */
  aux_lines(L, 1, 0);
  return 1;
}
示例#2
0
文件: liolib.c 项目: gitrider/wxsj2
static int f_read (lua_State *L) {
  return g_read(L, tofile(L, 1), 2);
}
示例#3
0
static int f_flush (lua_State *L) {
    return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
}
示例#4
0
文件: liolib.c 项目: gitrider/wxsj2
static FILE *getiofile (lua_State *L, const char *name) {
  lua_pushstring(L, name);
  lua_rawget(L, lua_upvalueindex(1));
  return tofile(L, -1);
}
示例#5
0
static int io_close (lua_State *L) {
    if (lua_isnone(L, 1))  /* no argument? */
        lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT);  /* use standard output */
    tofile(L);  /* make sure argument is an open stream */
    return aux_close(L);
}
示例#6
0
static int f_write (lua_State *L) {
    FILE *f = tofile(L);
    lua_pushvalue(L, 1);  /* push file at the stack top (to be returned) */
    return g_write(L, f, 2);
}
示例#7
0
文件: io.c 项目: Stefan-Schmidt/efl
static int
elua_flush(lua_State *L)
{
   return push_ret(L, fflush(tofile(L)) == 0, NULL);
}
示例#8
0
文件: leda-io.c 项目: salmito/leda
int leda_wrap_io(lua_State *L) {  
   FILE ** f=tofile(L,1);
   lua_pushlightuserdata(L,*f);
 	*f=NULL;
   return 1;
}
示例#9
0
/** \brief Set the argument offsets for a function, then kick off compiling
 *  of the function
 *
 *  \param prevarg  - Last argument
 *  \param currfn   - Current function
 */
void setlocvar(SYMBOL *prevarg,SYMBOL *currfn)
{
    int lgh,where;
    int *iptr;
    SYMBOL *copyarg;
    int argnumber;
    char buffer2[120];
    unsigned char tester;

	lgh = 0;  /* Initialise it */
    if ( prevarg != NULL && currfn->prototyped == 0 ) {
        StoreFunctionSignature(prevarg);
    }

    argnumber=currfn->prototyped;
    /*
     *      If we have filled up our number of arguments, then pretend
     *      we don't have any..nasty, nasty
     */
    if (argnumber==(MAXARGS-1)) argnumber=0;
    else   if (argnumber) argnumber=1;
    /*
     *      Dump some info about defining the function etc
     */
    if (verbose){
        toconsole();
        outstr("Defining function: "); outstr(currfn->name); nl();
        tofile();
    }

    nl();prefix();outname(currfn->name,dopref(currfn));col();nl();  /* print function name */

    infunc=1;       /* In a function for sure! */
    copyarg=prevarg;

    if ( ( (currfn->flags&SHARED) && makeshare ) || sharedfile ) {
        /* Shared library definition, offset the stack */
        where= 2 +shareoffset;
    } else
        where = 2 ;
    /* If we use frame pointer we preserve previous framepointer on entry
     * to each function
     */
#ifdef USEFRAME
	if (useframe) where+=2;
#endif
    while ( prevarg ) {
        lgh = 2 ;      /* Default length */
        /* This is strange, previously double check for ->type */
        if ( prevarg->type == LONG && prevarg->ident != POINTER )
            lgh=4;
        if ( prevarg->type == DOUBLE && prevarg->ident != POINTER )
            lgh=6;
		/* Far pointers */
		if ( (prevarg->flags&FARPTR)==FARPTR && prevarg->ident == POINTER)
			lgh=4;
        prevarg->size=lgh;
#ifdef CODSWALLOP
        /* All pointers are pushed onto the stack for functions as 4 bytes, if
         * needed, near pointers are padded out to compensate for this by dummy
         * loading with zero, this allows us to have one set of routines to
         * cope with this and hence solve a lot of duplication
         */
        if (prevarg->ident == POINTER && lpointer) lgh=4;
        prevarg->size=lgh;
#endif
        /*
         * Check the definition against prototypes here...
         */
        if (argnumber) {
            tester=CalcArgValue(prevarg->type,prevarg->ident,prevarg->flags);
            if (currfn->args[argnumber] != tester ) {
                if (currfn->args[argnumber] != PELLIPSES ) {
                    if (currfn->args[argnumber] == 0 ) {
                        warning(W_2MADECL);
                    } else {
                        if ( (currfn->args[argnumber]&PMASKSIGN) == (tester&PMASKSIGN) ) {
                            warning(W_SIGNARG);
                        } else {
                            error(E_ARGMIS1,currfn->name,currfn->prototyped-argnumber+1, ExpandArgValue(tester,buffer2,prevarg->tag_idx) );
                            error(E_ARGMIS2,ExpandArgValue(currfn->args[argnumber],buffer2, currfn->tagarg[argnumber]));
                        }
                    }
                }
            }
            argnumber++;
        }
        iptr = &prevarg->offset.i ;
        prevarg = prevarg->offset.p ;           /* follow ptr to prev. arg */
        *iptr = where ;                                         /* insert offset */
        where += lgh ;                                          /* calculate next offset */
    }
#ifdef USEFRAME
	pushframe();
#endif
	currfn->handled=YES;
    if (currfn->prototyped==1 && (currfn->flags&REGCALL) ) {
        /*
         * Fast call routine..
         */
        if (lgh==2) zpush();
        else if (lgh==4) lpush();
        else if (lgh==6) dpush();
        /* erk, if not matched, dodgy type! */
        copyarg->offset.i=-lgh;
        where=2;
    }

    stackargs=where;
    lstdecl=0;       /* Set number of local statics to zero */
    if ( statement() != STRETURN ) {
        if (lstdecl) postlabel(lstlab);
        lstdecl=0;
        /* do a statement, but if it's a return, skip */
        /* cleaning up the stack */
        leave(NO,NO) ;
    }
    CleanGoto();
    /* Asz80 needs a label at the end to sort out local symbols */
	if (asxx) {
        nl();prefix();
		outstr("smce_");
		outname(currfn->name,NO);
		col();nl();
	}
#ifdef INBUILT_OPTIMIZER
    generate();
#endif
    infunc = 0 ;                    /* not in fn. any more */
}
示例#10
0
static int io_close (lua_State *L) {
  if (lua_isnone(L, 1))
    LUA_IO_GETFIELD(IO_OUTPUT);
  tofile(L);  /* make sure argument is a file */
  return aux_close(L);
}
示例#11
0
文件: liolib.c 项目: zlandau/lua-safe
static int f_flush (lua_State *L) {
  SAFE_CHECK_FILE_MOD(L);
  return pushresult(L, fflush(tofile(L, 1)) == 0, NULL);
}
示例#12
0
文件: liolib.c 项目: RonDePrez/opentx
static int io_seek (lua_State *L) {
  FILE *f = tofile(L);
  lua_Unsigned offset = luaL_checkunsigned(L, 2);
  lua_pushinteger(L, f_lseek(f, offset));
  return 1;
}
示例#13
0
文件: leda-io.c 项目: salmito/leda
int leda_io_getfd(lua_State *L) {
   FILE ** f=tofile(L,1);
   int fd=fileno(*f);
   lua_pushinteger(L,fd);
   return 1;
}
示例#14
0
文件: liolib.c 项目: gitrider/wxsj2
static int f_write (lua_State *L) {
  return g_write(L, tofile(L, 1), 2);
}
示例#15
0
文件: liolib.c 项目: GodLesZ/svn-dump
static int io_close (lua_State *L) {
  if (lua_isnone(L, 1))
    lua_rawgeti(L, LUA_ENVIRONINDEX, IO_OUTPUT);
  tofile(L);  /* make sure argument is a file */
  return aux_close(L);
}
示例#16
0
文件: liolib.c 项目: gitrider/wxsj2
static int f_flush (lua_State *L) {
  return pushresult(L, fflush(tofile(L, 1)) == 0, NULL);
}
示例#17
0
文件: lgzip.c 项目: leonlee/tome
static int f_flush (lua_State *L) {
  return pushresult(L, gzflush(tofile(L, 1), Z_FINISH) == Z_OK, NULL);
}