File: Definition.c

package info (click to toggle)
openclonk 8.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 169,656 kB
  • sloc: cpp: 180,484; ansic: 108,988; xml: 31,371; python: 1,223; php: 767; makefile: 148; sh: 101; javascript: 34
file content (30 lines) | stat: -rw-r--r-- 878 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
	Definition.c
	Functions generally applicable to definitions.
	
	@author Maikel
*/

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.
// documented in /docs/sdk/script/fn
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 it 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, ...);
}