CommandHelper

CommandHelper

46.5k Downloads

way to see if an extension is loaded

LadyCailinBot opened this issue ยท 6 comments

commented

CMDHELPER-2882 - Reported by VergilPrime

Either return an array of extensions so I can if(array_contains(get_extensions(),'my_extension'))
or possibly load functions added by extensions into get_functions() so I can check to see if a custom function is in place.

commented

Comment by PseudoKnight

Some extension functions already load up in get_functions(). The real problem is that we can't appease the compiler if the function we use doesn't exist, even if we don't run it if we can't find it in get_functions(). The only way around this that I can think of is using eval() for each extension function we use, which is not a good solution.

commented

Comment by EntityReborn

I'll look into this once things in the extension management system settle down a bit. One thing to note, the extension in question must use the new lifecycle system for this to work! (This system is the only way to identify extensions, currently.)

commented

Comment by LadyCailin

To do this correctly, a deep compiler change will be needed. A compile time optimized function will need to be added, extension_loaded(), which will be able to run at compile time, and linking will have to be delayed until after branch optimization happens in the compiler.

commented

Comment by EntityReborn

Ah, I misread. Regardless, I'll later add a meta function that returns the events and functions registered by any given extension, in the format {'CommandHelperCore': {functions: {...}, events: {...}}, ...} etc.

commented

Comment by LadyCailin

Ok, function linking happens after optimization, and function_exists() has been added as well, as an optimized function.

This allows for "preprocessor" type directives, and will allow you to do if(function_exists('myfunction')){ myfunction() } in your code. The function_exists function is optimized, and will resolve to true or false before linking. If it returns false, then the code branch with myfunction() in it won't be included in the tree that is then later linked. This allows extensions to be checked for at compile time, and if they aren't installed, no compiler errors will happen. Other compilation errors, like syntax errors, etc. will still occur, so this isn't a stupid preprocessor directive like in C++. Also, related, but less relevant, event_exists has been added as well.

commented

Comment by VergilPrime

Damn you guys are efficient. Thanks!