make GetDefinition work on string parameter

This can be useful to check if a definition is loaded, ideally the implementation is moved to the engine.
liquid_container
Maikel de Vries 2016-03-20 09:15:24 +01:00
parent b50a059350
commit 8d2ab69d03
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
/*--
Definition.c
Authors: Maikel
Functions generally applicable to definitions.
--*/
static GetDefinition_Loaded_Definition_List;
// Returns the definition or nil if par is a string and the definition exists.
// See the documentation for the case when par is an integer.
global func GetDefinition(par)
{
// Overload behavior when par is a string.
if (GetType(par) == C4V_String)
{
if (GetDefinition_Loaded_Definition_List == nil)
{
// Fill the static list of definitions when is has not been generated yet.
GetDefinition_Loaded_Definition_List = {};
var i = 0, def;
while (def = GetDefinition(i++))
GetDefinition_Loaded_Definition_List[Format("%i", def)] = def;
}
// Return the definition if in the list and nil otherwise.
return GetDefinition_Loaded_Definition_List[par];
}
return _inherited(par, ...);
}