Raised This Month: $12 Target: $400
 3% 

Solved Plugin dependencies (Natives)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 11-05-2016 , 13:17   Plugin dependencies (Natives)
Reply With Quote #1

Hi everyone,

I have two plugins A & B. My plugin B needs to use a native from the plugin A.

Plugin A:
PHP Code:
Handle gl_my_forward;

public 
void OnPluginStart()
{
    
gl_my_forward CreateForward(ET_IgnoreParam_Cell);
}

/* ... AskPluginLoad2 ... */

public int my_native_fct(Handle hPluginint iNumParams)
{
    
AddToForward(gl_my_forwardhPluginGetNativeFunction(1));
    return 
0;

Plugin B:
PHP Code:
public void OnPluginStart()
{
    
my_native(xxxxxxxx);

---------------------
My issue is that "OnPluginStart()" of the plugin B is called before "OnPluginStart()" of the plugin A. This means that the global variable "gl_my_forward" isn't still initialized in the plugin A ==> Error.

Is it the normal behavior? Is there a clean solution to this issue?

Thank you
__________________

Last edited by micapat; 11-05-2016 at 18:43.
micapat is offline
DJ Tsunami
DJ Post Spammer
Join Date: Feb 2008
Location: The Netherlands
Old 11-05-2016 , 14:00   Re: Plugin dependencies (Natives)
Reply With Quote #2

Yes, this is normal behavior as plugins can be loaded in any order.

Are you calling RegPluginLibrary("yourpluginname") inside AskPluginLoad2() in plugin A? If so, to check if plugin A is loaded:

Plugin B:
PHP Code:
public void OnPluginStart()
{
    if (
LibraryExists("yourpluginname")) {
        
my_native(xxxxxxxx);
    }
}

public 
void OnLibraryAdded(const char[] name)
{
    if (
StrEqual(name"yourpluginname")) {
        
my_native(xxxxxxxx);
    }

There is also OnAllPluginsLoaded() which I've never used, so not sure if it has other side effects.
__________________
Advertisements | REST in Pawn - HTTP client for JSON REST APIs
Please do not PM me with questions. Post in the plugin thread.
DJ Tsunami is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 11-05-2016 , 17:05   Re: Plugin dependencies (Natives)
Reply With Quote #3

As Tsunami said, plugins do not load in a defined order. You should not call the other plugin's natives till OnAllPluginsLoaded since they may not exist earlier than that (and you also shouldn't call LibraryExists till then for the same reason; the library may not yet exist).

RegPluginLibrary/LibraryExists/MarkNativeAsOptional are useful when you want another plugin to not be a hard dependency but only optional.
Fyren is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 11-05-2016 , 18:43   Re: Plugin dependencies (Natives)
Reply With Quote #4

Ok, thank you for your help! I will use OnAllPluginsLoaded() then.
__________________
micapat is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:47.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode