bool CScriptStorage::print_output(lua_State *L, LPCSTR caScriptFileName, int iErorCode) { if (iErorCode) print_error (L,iErorCode); if (!lua_isstring(L,-1)) return (false); LPCSTR S = lua_tostring(L,-1); if (!xr_strcmp(S,"cannot resume dead coroutine")) { VERIFY2 ("Please do not return any values from main!!!",caScriptFileName); #ifdef USE_DEBUGGER # ifndef USE_LUA_STUDIO if(ai().script_engine().debugger() && ai().script_engine().debugger()->Active() ){ ai().script_engine().debugger()->Write(S); ai().script_engine().debugger()->ErrorBreak(); } # endif // #ifndef USE_LUA_STUDIO #endif // #ifdef USE_DEBUGGER } else { if (!iErorCode) script_log (ScriptStorage::eLuaMessageTypeInfo,"Output from %s",caScriptFileName); script_log (iErorCode ? ScriptStorage::eLuaMessageTypeError : ScriptStorage::eLuaMessageTypeMessage,"%s",S); #ifdef USE_DEBUGGER # ifndef USE_LUA_STUDIO if (ai().script_engine().debugger() && ai().script_engine().debugger()->Active()) { ai().script_engine().debugger()->Write (S); ai().script_engine().debugger()->ErrorBreak (); } # endif // #ifndef USE_LUA_STUDIO #endif // #ifdef USE_DEBUGGER } return (true); }
bool CScriptStorage::print_output(lua_State *L, LPCSTR caScriptFileName, int iErorCode) { if (iErorCode) print_error(L, iErorCode); if (!lua_isstring(L,-1)) return (false); LPCSTR S = lua_tostring(L,-1); if (!xr_strcmp(S,"cannot resume dead coroutine")) { VERIFY2 ("Please do not return any values from main!!!",caScriptFileName); #ifdef USE_DEBUGGER if(ai().script_engine().debugger() && ai().script_engine().debugger()->Active() ){ ai().script_engine().debugger()->Write(S); ai().script_engine().debugger()->ErrorBreak(); } #endif } else { if (!iErorCode) script_log (ScriptStorage::eLuaMessageTypeInfo,"Output from %s",caScriptFileName); script_log (iErorCode ? ScriptStorage::eLuaMessageTypeError : ScriptStorage::eLuaMessageTypeMessage,"%s",S); #ifdef USE_DEBUGGER if (iErorCode) { if (strstr(S, "no overload of 'net_packet:r_vec3'")) // при загрузке серверных объектов выполн¤ютс¤ их кор¤вые скрипты с тыщей таких ошибок :( return (true); Msg("!LUA_ERROR: %s", S); #ifdef LUAICP_COMPAT lua_getglobal(L, "DebugDumpAll"); lua_pcall(L, 0, 0, -1); #else LPCSTR traceback = get_lua_traceback(L, 0); Msg("! %s", caScriptFileName, iErorCode, traceback); #endif } if (ai().script_engine().debugger() && ai().script_engine().debugger()->Active()) { ai().script_engine().debugger()->Write (S); ai().script_engine().debugger()->ErrorBreak (); } #endif } return (true); }
/* attaches room vnum to msg and sends it to script_log */ void wld_log(room_data * room, const char *msg) { char buf[MAX_INPUT_LENGTH + 100]; sprintf(buf, "(Room: %d, trig: %d): %s", room->number, last_trig_vnum, msg); script_log(buf); }
bool CScriptStorage::parse_namespace(LPCSTR caNamespaceName, LPSTR b, LPSTR c) { strcpy (b,""); strcpy (c,""); LPSTR S2 = xr_strdup(caNamespaceName); LPSTR S = S2; for (int i=0;;++i) { if (!xr_strlen(S)) { script_log (ScriptStorage::eLuaMessageTypeError,"the namespace name %s is incorrect!",caNamespaceName); xr_free (S2); return (false); } LPSTR S1 = strchr(S,'.'); if (S1) *S1 = 0; if (i) strcat (b,"{"); strcat (b,S); strcat (b,"="); if (i) strcat (c,"}"); if (S1) S = ++S1; else break; } xr_free (S2); return (true); }
void CScriptEngine::register_script_classes() { #ifdef DBG_DISABLE_SCRIPTS return; #endif string_path S; FS.update_path(S, "$game_config$", "script.ltx"); CInifile *l_tpIniFile = xr_new<CInifile>(S); R_ASSERT(l_tpIniFile); if (!l_tpIniFile->section_exist("common")) { xr_delete(l_tpIniFile); return; } m_class_registrators = READ_IF_EXISTS(l_tpIniFile, r_string, "common", "class_registrators", ""); xr_delete(l_tpIniFile); u32 n = _GetItemCount(*m_class_registrators); string256 I; for (u32 i = 0; i < n; ++i) { _GetItem(*m_class_registrators, i, I); luabind::functor<void> result; if (!functor(I, result)) { script_log(eLuaMessageTypeError, "Cannot load class registrator %s!", I); continue; } result(const_cast<CObjectFactory*>(&object_factory())); } }
/* attaches object name and vnum to msg and sends it to script_log */ void obj_log(obj_data *obj, char *msg) { char buf[MAX_INPUT_LENGTH + 100]; sprintf(buf, "Obj (%s, VNum %d): %s", obj->short_description, GET_OBJ_VNUM(obj), msg); script_log(buf); }
/* attaches room vnum to msg and sends it to script_log */ void wld_log(room_data *room, char *msg) { char buf[MAX_INPUT_LENGTH + 100]; void script_log(char *msg); sprintf(buf, "Wld (room %d): %s", room->number, msg); script_log(buf); }
bool CScriptStorage::do_file (LPCSTR caScriptName, LPCSTR caNameSpaceName) { int start = lua_gettop(lua()); string_path l_caLuaFileName; IReader *l_tpFileReader = FS.r_open(caScriptName); if (!l_tpFileReader) { script_log (eLuaMessageTypeError,"Cannot open file \"%s\"",caScriptName); return (false); } strconcat (sizeof(l_caLuaFileName),l_caLuaFileName,"@",caScriptName); if (!load_buffer(lua(),static_cast<LPCSTR>(l_tpFileReader->pointer()),(size_t)l_tpFileReader->length(),l_caLuaFileName,caNameSpaceName)) { // VERIFY (lua_gettop(lua()) >= 4); // lua_pop (lua(),4); // VERIFY (lua_gettop(lua()) == start - 3); lua_settop (lua(),start); FS.r_close (l_tpFileReader); return (false); } FS.r_close (l_tpFileReader); int errFuncId = -1; #ifdef USE_DEBUGGER # ifndef USE_LUA_STUDIO if( ai().script_engine().debugger() ) errFuncId = ai().script_engine().debugger()->PrepareLua(lua()); # endif // #ifndef USE_LUA_STUDIO #endif // #ifdef USE_DEBUGGER if (0) //. { for (int i=0; lua_type(lua(), -i-1); i++) Msg ("%2d : %s",-i-1,lua_typename(lua(), lua_type(lua(), -i-1))); } // because that's the first and the only call of the main chunk - there is no point to compile it // luaJIT_setmode (lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_OFF); // Oles int l_iErrorCode = lua_pcall(lua(),0,0,(-1==errFuncId)?0:errFuncId); // new_Andy // luaJIT_setmode (lua(),0,LUAJIT_MODE_ENGINE|LUAJIT_MODE_ON); // Oles #ifdef USE_DEBUGGER # ifndef USE_LUA_STUDIO if( ai().script_engine().debugger() ) ai().script_engine().debugger()->UnPrepareLua(lua(),errFuncId); # endif // #ifndef USE_LUA_STUDIO #endif // #ifdef USE_DEBUGGER if (l_iErrorCode) { #ifdef DEBUG print_output(lua(),caScriptName,l_iErrorCode); #endif on_error (lua()); lua_settop (lua(),start); return (false); } return (true); }
/* attaches mob's name and vnum to msg and sends it to script_log */ void mob_log(char_data *mob, char *msg) { char buf[MAX_INPUT_LENGTH + 100]; void script_log(char *msg); sprintf(buf, "Mob (%s, VNum %d): %s", GET_SHORT(mob), GET_MOB_VNUM(mob), msg); script_log(buf); }
void CScriptStorage::print_stack () { if (!m_stack_is_ready) return; m_stack_is_ready = false; lua_State *L = lua(); lua_Debug l_tDebugInfo; for (int i=0; lua_getstack(L,i,&l_tDebugInfo);++i ) { lua_getinfo (L,"nSlu",&l_tDebugInfo); if (!l_tDebugInfo.name) script_log (ScriptStorage::eLuaMessageTypeError,"%2d : [%s] %s(%d) : %s",i,l_tDebugInfo.what,l_tDebugInfo.short_src,l_tDebugInfo.currentline,""); else if (!xr_strcmp(l_tDebugInfo.what,"C")) script_log (ScriptStorage::eLuaMessageTypeError,"%2d : [C ] %s",i,l_tDebugInfo.name); else script_log (ScriptStorage::eLuaMessageTypeError,"%2d : [%s] %s(%d) : %s",i,l_tDebugInfo.what,l_tDebugInfo.short_src,l_tDebugInfo.currentline,l_tDebugInfo.name); } }
void CScriptStorage::print_error(lua_State *L, int iErrorCode) { switch (iErrorCode) { case LUA_ERRRUN : { script_log (ScriptStorage::eLuaMessageTypeError,"SCRIPT RUNTIME ERROR"); break; } case LUA_ERRMEM : { script_log (ScriptStorage::eLuaMessageTypeError,"SCRIPT ERROR (memory allocation)"); break; } case LUA_ERRERR : { script_log (ScriptStorage::eLuaMessageTypeError,"SCRIPT ERROR (while running the error handler function)"); break; } case LUA_ERRFILE : { script_log (ScriptStorage::eLuaMessageTypeError,"SCRIPT ERROR (while running file)"); break; } case LUA_ERRSYNTAX : { script_log (ScriptStorage::eLuaMessageTypeError,"SCRIPT SYNTAX ERROR"); break; } case LUA_YIELD : { script_log (ScriptStorage::eLuaMessageTypeInfo,"Thread is yielded"); break; } default : NODEFAULT; } }
/* code borrowed from do_cast() */ void do_dg_cast(void *go, struct script_data *sc, trig_data *trig, int type, char *cmd) { struct char_data *caster = NULL; struct char_data *tch = NULL; struct obj_data *tobj = NULL; struct room_data *caster_room = NULL; char *s, *t; int spellnum, target = 0; /* need to get the caster or the room of the temporary caster */ switch (type) { case MOB_TRIGGER: caster = (struct char_data *)go; break; case WLD_TRIGGER: caster_room = (struct room_data *)go; break; case OBJ_TRIGGER: caster_room = dg_room_of_obj((struct obj_data *)go); if (!caster_room) { script_log("dg_do_cast: unknown room for object-caster!"); return; } break; default: script_log("dg_do_cast: unknown trigger type!"); return; } /* get: blank, spell name, target name */ s = strtok(cmd, "'"); if (s == NULL) { sprintf(buf2, "Trigger: %s, VNum %d. dg_cast needs spell name.", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig)); script_log(buf2); return; } s = strtok(NULL, "'"); if (s == NULL) { sprintf(buf2, "Trigger: %s, VNum %d. dg_cast needs spell name in `'s.", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig)); script_log(buf2); return; } t = strtok(NULL, "\0"); /* spellnum = search_block(s, spells, 0); */ spellnum = find_abil_num(s,spells); if ((spellnum < 1) || (spellnum > MAX_SPELLS)) { sprintf(buf2, "Trigger: %s, VNum %d. dg_cast: invalid spell name (%s)", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), cmd); script_log(buf2); return; } /* Find the target */ if (t != NULL) { one_argument(strcpy(arg, t), t); skip_spaces(&t); } if (IS_SET(SINFO.targets, TAR_IGNORE)) { target = TRUE; } else if (t != NULL && *t) { if (!target && (IS_SET(SINFO.targets, TAR_CHAR_ROOM) || IS_SET(SINFO.targets, TAR_CHAR_WORLD))) { if ((tch = get_char(t)) != NULL) target = TRUE; } if (!target && (IS_SET(SINFO.targets, TAR_OBJ_INV) || IS_SET(SINFO.targets, TAR_OBJ_EQUIP) || IS_SET(SINFO.targets, TAR_OBJ_ROOM) || IS_SET(SINFO.targets, TAR_OBJ_WORLD))) { if ((tobj = get_obj(t)) != NULL) target = TRUE; } if (!target) { sprintf(buf2, "Trigger: %s, VNum %d. dg_cast: target not found (%s)", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), cmd); script_log(buf2); return; } } if (IS_SET(SINFO.routines, MAG_GROUPS)) { sprintf(buf2, "Trigger: %s, VNum %d. dg_cast: group spells not permitted (%s)", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), cmd); script_log(buf2); return; } if (!caster) { caster = read_mobile(DG_CASTER_PROXY, VIRTUAL); if (!caster) { script_log("dg_cast: Cannot load the caster mob!"); return; } /* set the caster's name to that of the object, or the gods.... */ /* take select pieces from char_to_room(); */ if (type==OBJ_TRIGGER) caster->player.short_descr = str_dup(((struct obj_data *)go)->short_description); else if (type==WLD_TRIGGER) caster->player.short_descr = str_dup("The gods"); caster->next_in_room = caster_room->people; caster_room->people = caster; caster->in_room = real_room(caster_room->number); call_magic(caster, tch, tobj, spellnum, ABT_SPELL, GET_LEVEL(caster), CAST_SPELL, FALSE); extract_char(caster); } else call_magic(caster, tch, tobj, spellnum, ABT_SPELL, GET_LEVEL(caster), CAST_SPELL, FALSE); }
void do_dg_affect(void *go, struct script_data *sc, trig_data *trig, int script_type, char *cmd) { struct char_data *ch = NULL; int value=0, duration=0; char junk[MAX_INPUT_LENGTH]; /* will be set to "dg_affect" */ char charname[MAX_INPUT_LENGTH], property[MAX_INPUT_LENGTH]; char value_p[MAX_INPUT_LENGTH], duration_p[MAX_INPUT_LENGTH]; int index=0, type=0; struct affected_type af; half_chop(cmd, junk, cmd); half_chop(cmd, charname, cmd); half_chop(cmd, property, cmd); half_chop(cmd, value_p, duration_p); /* make sure all parameters are present */ if (!charname || !*charname || !property || !*property || !value_p || !*value_p || !duration_p || !*duration_p) { sprintf(buf2, "Trigger: %s, VNum %d. dg_affect usage: <target> <property> <value> <duration>", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig)); script_log(buf2); return; } value = atoi(value_p); duration = atoi(duration_p); if (duration <= 0) { sprintf(buf2, "Trigger: %s, VNum %d. dg_affect: need positive duration!", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig)); script_log(buf2); return; } /* find the property -- first search apply_types */ index = 0; while (str_cmp(apply_types[index], "\n")) { if (!str_cmp(apply_types[index], property)) { type=APPLY_TYPE; break; } index++; } if (!type) { /* search affect_types now */ index = 0; while (str_cmp(affected_bits[index], "\n")) { if (!str_cmp(affected_bits[index], property)) { type=AFFECT_TYPE; break; } index++; } } if (!type) { /* property not found */ sprintf(buf2, "Trigger: %s, VNum %d. dg_affect: unknown property '%s'!", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig), property); script_log(buf2); return; } /* locate the target */ ch = get_char(charname); if (!ch) { sprintf(buf2, "Trigger: %s, VNum %d. dg_affect: cannot locate target!", GET_TRIG_NAME(trig), GET_TRIG_VNUM(trig)); script_log(buf2); return; } /* add the affect */ af.type = 0; af.duration = duration; af.modifier = value; af.location = 0; af.bitvector = (1<<type); affect_to_char(ch, &af); }