* fixed possible crash when script list was deleted and after that the script got executed
* fixed wrong check for #mark and #tip at script loading * misc stuff
This commit is contained in:
parent
924b8404c4
commit
0aed2ee895
@ -44,7 +44,7 @@ add,counter 1
|
||||
#script=hook_example_cleanup
|
||||
//----------------------------------
|
||||
unloaddef hook_example_new
|
||||
// other possible way: lclear DEFSCRIPT::SCRIPT::hook_example_new
|
||||
// other possible, but wrong way: delete DEFSCRIPT::SCRIPT::hook_example_new
|
||||
|
||||
|
||||
|
||||
@ -53,4 +53,4 @@ unloaddef hook_example_new
|
||||
#script=dummy
|
||||
#onload
|
||||
hook_example_hooker
|
||||
#/onload
|
||||
#/onload
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
using namespace DefScriptTools;
|
||||
|
||||
#define SN_ONLOAD "?onload?"
|
||||
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
|
||||
|
||||
enum DefScriptBlockType
|
||||
{
|
||||
@ -316,7 +315,7 @@ bool DefScriptPackage::LoadScriptFromFile(std::string fn){
|
||||
DeleteScript(SN_ONLOAD);
|
||||
curScript=Script[sn];
|
||||
}
|
||||
else if(strcmp(line.c_str(),"tag")==0 || strcmp(line.c_str(),"mark")==0)
|
||||
else if(strncmp(line.c_str(),"tag",3)==0 || strncmp(line.c_str(),"mark",4)==0)
|
||||
{
|
||||
curScript->AddLine("#" + line);
|
||||
}
|
||||
|
||||
@ -35,4 +35,6 @@ enum VariableType
|
||||
|
||||
typedef long double ldbl;
|
||||
|
||||
#define SCRIPT_NAMESPACE "DEFSCRIPT::SCRIPT::"
|
||||
|
||||
#endif
|
||||
@ -45,7 +45,16 @@ DefReturnResult DefScriptPackage::func_lpopfront(CmdSet& Set)
|
||||
// delete a list and all its elements
|
||||
DefReturnResult DefScriptPackage::func_ldelete(CmdSet& Set)
|
||||
{
|
||||
lists.Delete(_NormalizeVarName(Set.defaultarg,Set.myname));
|
||||
std::string lname = _NormalizeVarName(Set.defaultarg,Set.myname);
|
||||
if(strncmp(lname.c_str(), SCRIPT_NAMESPACE,strlen(SCRIPT_NAMESPACE))==0)
|
||||
{
|
||||
printf("DefScript: WARNING: ldelete used on a script list, clearing instead! (called by '%s', list '%s')\n",Set.myname.c_str(), lname.c_str());
|
||||
DefList *l = lists.GetNoCreate(lname);
|
||||
if(l)
|
||||
l->clear();
|
||||
return true;
|
||||
}
|
||||
lists.Delete(lname);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -14,6 +14,8 @@ public:
|
||||
T *GetNoCreate(std::string);
|
||||
void Assign(std::string,T*);
|
||||
void Unlink(std::string);
|
||||
void UnlinkByPtr(T*);
|
||||
std::string GetNameByPtr(T*);
|
||||
|
||||
private:
|
||||
T *_Create(std::string);
|
||||
@ -93,5 +95,29 @@ template<class T> void TypeStorage<T>::Unlink(std::string s)
|
||||
_storage.erase(s);
|
||||
}
|
||||
|
||||
// removes the pointer from the storage without deleting it, if name is unknown
|
||||
template<class T> void TypeStorage<T>::UnlinkByPtr(T *ptr)
|
||||
{
|
||||
for(std::map<std::string,T*>::iterator it = _storage.begin(); it != _storage.end();)
|
||||
{
|
||||
if(it->second == ptr)
|
||||
{
|
||||
Unlink(it->first);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T> std::string TypeStorage<T>::GetNameByPtr(T *ptr)
|
||||
{
|
||||
for(std::map<std::string,T*>::iterator it = _storage.begin(); it != _storage.end();)
|
||||
{
|
||||
if(it->second == ptr)
|
||||
{
|
||||
return it->first;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user