static void io_writeto() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FOUTPUT); setreturn(2, FOUTPUT); } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current->isOpen()) { pushresult(0); return; } setreturn(id, FOUTPUT); } else { Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\'); LuaFile *current; Common::WriteStream *outFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); outFile = saveFileMan->openForSaving(s); if (!outFile) { pushresult(0); return; } current = new LuaFile(); current->_out = outFile; current->_filename = s; setreturn(addfile(current), FOUTPUT); } }
static void io_readfrom() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FINPUT); setreturn(1, FINPUT); } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current) { pushresult(0); return; } setreturn(id, FINPUT); } else { const char *s = luaL_check_string(FIRSTARG); LuaFile *current; Common::SeekableReadStream *inFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); inFile = saveFileMan->openForLoading(s); if (!inFile) current = g_resourceloader->openNewStreamLuaFile(s); else { current = new LuaFile(); current->_in = inFile; current->_filename = s; } if (!current) { delete current; pushresult(0); } else { setreturn(addfile(current), FINPUT); } } }
static int io_appendto (lua_State *L) { IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); FILE *current; lua_pop(L, 1); /* remove upvalue */ current = fopen(luaL_check_string(L, 1), "a"); return setreturn(L, ctrl, current, OUTFILE); }
static void io_appendto() { Common::String s = Common::lastPathComponent(luaL_check_string(FIRSTARG), '\\'); Common::SeekableReadStream *inFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); inFile = saveFileMan->openForLoading(s); if (!inFile) { pushresult(0); return; } int size = inFile->size(); byte *buf = new byte[size]; inFile->read(buf, size); delete inFile; Common::WriteStream *outFile = NULL; outFile = saveFileMan->openForSaving(s); if (!outFile) pushresult(0); else { outFile->write(buf, size); LuaFile *current = new LuaFile(); current->_out = outFile; current->_filename = s; setreturn(addfile(current), FOUTPUT); } delete[] buf; }
static void io_appendto (void) { char *s = luaL_check_string(FIRSTARG); FILE *fp = fopen (s, "a"); if (fp != NULL) setreturn(fp, FOUTPUT); else pushresult(0); }
/* ----> Create an alarm <---- */ dbref create_alarm(CONTEXT) { dbref alarm,owner = (!in_command && (Uid(player) != player)) ? Uid(player):Owner(player); setreturn(ERROR,COMMAND_FAIL); if(Level3(Owner(player))) { if(!Blank(arg1)) { if(strlen(arg1) <= 128) { if(ok_name(arg1)) { if(adjustquota(player,owner,ALARM_QUOTA)) { /* ----> Create and initialise alarm <---- */ alarm = new_object(); db[alarm].destination = NOTHING; db[alarm].location = player; db[alarm].flags = OBJECT; db[alarm].owner = owner; db[alarm].type = TYPE_ALARM; if(!in_command && (Uid(player) == owner) && friendflags_set(owner,player,NOTHING,FRIEND_SHARABLE)) db[alarm].flags |= SHARABLE; ansi_code_filter((char *) arg1,arg1,1); initialise_data(alarm); setfield(alarm,NAME,arg1,1); setfield(alarm,DESC,arg2,0); stats_tcz_update_record(0,0,0,1,0,0,0); PUSH(alarm,db[player].fuses); if(!in_command) output(getdsc(player),player,0,1,0,ANSI_LGREEN"Alarm "ANSI_LWHITE"%s"ANSI_LGREEN" created with ID "ANSI_LYELLOW"#%d"ANSI_LGREEN".",getfield(alarm,NAME),alarm); else writelog(HACK_LOG,1,"HACK","Alarm %s(%d) created within compound command %s(%d) owned by %s(%d).",getname(alarm),alarm,getname(current_command),current_command,getname(Owner(current_command)),Owner(current_command)); setreturn(getnameid(player,alarm,NULL),COMMAND_SUCC); return(alarm); } else warnquota(player,owner,"to build an alarm"); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, an alarm can't have that name."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, the maximum length of an alarm's name is 128 characters."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Please specify a name for the new alarm."); } else output(getdsc(player),player,0,1,0,ANSI_LGREEN"Sorry, only Wizards/Druids and above can create an alarm."); return(NOTHING); }
static void io_readfrom() { lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { if (getfile(FOUTPUT) != getfile(1)) { closefile(FINPUT); setreturn(1, FINPUT); } } else if (lua_tag(f) == gettag(IOTAG)) { int32 id = lua_getuserdata(f); LuaFile *current = getfile(id); if (!current) { pushresult(0); return; } setreturn(id, FINPUT); } else { const char *s = luaL_check_string(FIRSTARG); Common::String fileName = Common::lastPathComponent(s, '\\'); LuaFile *current = NULL; Common::SeekableReadStream *inFile = NULL; Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); inFile = saveFileMan->openForLoading(fileName); if (!inFile) { inFile = g_resourceloader->openNewStreamFile(s); } if (inFile) { current = new LuaFile(); current->_in = inFile; current->_filename = s; } else { warning("liolib.cpp, io_readfrom(): Could not open file %s", s); } if (!current) { delete current; pushresult(0); } else { setreturn(addfile(current), FINPUT); } } }
static int io_fromto (lua_State *L, int inout, const char *mode) { IOCtrl *ctrl = (IOCtrl *)lua_touserdata(L, -1); FILE *current; lua_pop(L, 1); /* remove upvalue */ if (lua_isnull(L, 1)) { closefile(L, ctrl, getfilebyref(L, ctrl, inout)); current = (inout == 0) ? stdin : stdout; } else if (lua_tag(L, 1) == ctrl->iotag) /* deprecated option */ current = (FILE *)lua_touserdata(L, 1); else { const char *s = luaL_check_string(L, 1); current = (*s == '|') ? popen(s+1, mode) : fopen(s, mode); } return setreturn(L, ctrl, current, inout); }
static void io_writeto (void) { FILE *current; lua_Object f = lua_getparam(FIRSTARG); if (f == LUA_NOOBJECT) { closefile(FOUTPUT); current = stdout; } else if (lua_tag(f) == gettag(IOTAG)) current = lua_getuserdata(f); else { char *s = luaL_check_string(FIRSTARG); current = (*s == '|') ? popen(s+1,"w") : fopen(s,"w"); if (current == NULL) { pushresult(0); return; } } setreturn(current, FOUTPUT); }