public static int stat(CharPtr filename, stat_struct st) { if (File.Exists(filename.ToString())) { return(0); } else { return(-1); } }
/* ** Open a file to write appended. ** LUA interface: ** status = appendto (filename) ** where: ** status = 2 -> success (already exist) ** status = 1 -> success (new file) ** status = 0 -> error */ private static void io_appendto() { lua_Object o = lua_getparam(1); if (o == LUA_NOOBJECT) /* restore standart output */ { if (@out != stdout) { fclose(@out); @out = stdout; } lua_pushnumber(1); } else { if (0 == lua_isstring(o)) { lua_error("incorrect argument to function 'appendto`"); lua_pushnumber(0); } else { int r; FILE fp; stat_struct st = new stat_struct(); if (stat(lua_getstring(o), st) == -1) { r = 1; } else { r = 2; } fp = fopen(lua_getstring(o), "a"); if (fp == null) { lua_pushnumber(0); } else { if (@out != stdout) { fclose(@out); } @out = fp; lua_pushnumber(r); } } } }