Coder Social home page Coder Social logo

Comments (14)

Misiur avatar Misiur commented on June 11, 2024

It's a known PAWN compiler issue. Use OnPlayerEnterRaceCP / OnPlayerEnterDynamicRaceCP instead. I'm not certain if Zeex's compiler allows currently for longer symbol names, if yes it might be added as a feature.

from ysi-includes.

Ahmad45123 avatar Ahmad45123 commented on June 11, 2024

IK its a PAWN problem.

What actually happens is that y_hooks uses a long prefix behind the function name.
if that prefix can be lowered to lets say one char... it'll work great.

from ysi-includes.

mokiding avatar mokiding commented on June 11, 2024

Zeex same error compiler too ...

public OnPlayerEnterRaceCheckpoint(playerid)
{
 return 1;
}
hook OnPlayerEnterRaceCheckpoint(playerid)
{
 SendClientMessage(playerid, -1, "You entered to raceCheckPoint");
}

from ysi-includes.

Misiur avatar Misiur commented on June 11, 2024

The problem with 1 char prefix would be a lot of namespace and macro clashes. First character can be only from @a-zA-Z range, and most YSI libraries use @Something prefixes, so this might be a problem. if we prefixed with @ only for example.

from ysi-includes.

Ahmad45123 avatar Ahmad45123 commented on June 11, 2024

You may be right but that's the only way... And you said I can just use
OnPlayerEnterRaceCP.. How can I rename callbacks :
On May 12, 2015 2:37 PM, "Misiur" [email protected] wrote:

The problem with 1 char prefix would be a lot of namespace and macro
clashes. First character can be only from @a-zA-Z range, and most YSI
libraries use @something prefixes, so this might be a problem. if we
prefixed with @ only for example.


Reply to this email directly or view it on GitHub
https://github.com/Misiur/YSI-Includes/issues/14#issuecomment-101246897.

from ysi-includes.

Misiur avatar Misiur commented on June 11, 2024

I'm not certain what your problem is? If you don't want to go one by one, you can always run search and replace with regex on your project: (hook OnPlayerEnter)(Dynamic)?(Race)Checkpoint -> $1$2$3CP

from ysi-includes.

Ahmad45123 avatar Ahmad45123 commented on June 11, 2024

I mean its a SAMP callback, And its set to OnPlayerEnterRaceCheckpoint.
If I renamed it from hook OnPlayerEnterRaceCheckpoint(playerid) to hook OnPlayerEnterRaceCP(playerid).

Will it work ? I dont think so... :/

from ysi-includes.

maddinat0r avatar maddinat0r commented on June 11, 2024

It WILL work. Take a look here, those replacements are clearly defined.

from ysi-includes.

Ahmad45123 avatar Ahmad45123 commented on June 11, 2024

Ahhhhhhhhhhh I never saw that tbh.. @Misiur Explain it better next time please :P

Thanks @maddinat0r

And also, I can add more.. right ?

from ysi-includes.

Misiur avatar Misiur commented on June 11, 2024

Yup. Also keep in mind that each hook for same callback has unique (sequential) identifier, such as @yH_OnILikeMudkipz@132, so you'll need even more characters.

(That yup was for @maddinat0r post)

from ysi-includes.

Y-Less avatar Y-Less commented on June 11, 2024

Note: maddinat0r et. al. replied while I was writing this, so the first bit was from before they posted...

Have you tried?

https://github.com/Misiur/YSI-Includes/blob/f4d85a8d1c7552618c0546d3f93d5ef625ed59c5/YSI_Coding/y_hooks/impl.inc#L148-L160

This is the ONLY work-around. It can't be "fixed" in the compiler because the runtime doesn't support longer names either. And it can't be "fixed" by using shorter suffixes and prefixes for several reasons. Firstly, the final name for a function such as "hook OnPlayerConnect" is:

@yH_OnPlayerConnect@012

Let's look at the components:

  1. @yH_ This seems like the most obvious candidate for shortening, but it serves two purposes:

    1. The prefix (almost) removes any chance of a naming collision with user code. Many YSI generated functions start with a combination of @, _, y, and X where X is upper case and depends on the exact library (here "H" for "hooks"). The @ being first makes the function public (often explicitly as you don't need the public keyword in that case), static ones usually start with _, others are y_@X or similar.
    2. @yH_, in the compiled AMX, is 4 bytes, or one cell. This fact is an important one in setting up the system because y_hooks scans for that cell here: https://github.com/Misiur/YSI-Includes/blob/f4d85a8d1c7552618c0546d3f93d5ef625ed59c5/YSI_Coding/y_hooks/impl.inc#L582 Using "AMX_GetPublicNamePrefix" is a fast search method that looks for 4 bytes at once, instead of doing a string comparison.
  2. The resulting function name must be unique. This is done in y_hooks by repeatedly re-including y_unique, which generates a new 3 digit number each time it is included to cater for up to 1000 includes. This could be reduced to 2 digits, or even 1 digit, by using base 62 (0-9, a-z, A-Z), but 1 digit would severely limit the usefulness of the include because it is actually included far more times than specific functions are hooked. 2 base-62 digits would enable up to 3844 unique function names, vastly MORE than the current implementation, but at a severely reduced level of readability. The uniqueness identifier is appended, and separated from the name by @. We could prefix the uniqueness name (I'm actually not sure why it isn't in retrospect). So we can reduce the function to:

    @yH_0COnPlayerConnect

    With no need for a separator after the unique number since it is a constant length (2 characters, for consistent orderings in the header).

In conclusion, we saved two characters, which still isn't enough for some callbacks, so a more generic solution was devised.

from ysi-includes.

Y-Less avatar Y-Less commented on June 11, 2024

Also, I thought I had written code to make replacements generic, such that you could do:

DEFINE_HOOK_REPLACEMENT(Checkpoint, CP);

Outside of any code, and then libraries could quickly add their own. As it is, apparently I just have them hard-coded...

Something like:

#if !defined MAX_HOOK_REPLACEMENTS
    #define MAX_HOOK_REPLACEMENTS (16)
#endif

// Generate a function name using only ONE of the parts, so two replacements for
// the same long name will collide at compile-time
#define DEFINE_HOOK_REPLACEMENT(%0,%1); forward @_yH%0(); public @_yH%0() { _Hooks_AddReplacement(#%0, #%1); }

// Strip spaces from the generated function name.
#define @_yH%0\32;%1(%2) @_yH%0%1(%2)

// Create the default replacements.
DEFINE_HOOK_REPLACEMENT(Checkpoint, CP );
DEFINE_HOOK_REPLACEMENT(Container , Cnt);
DEFINE_HOOK_REPLACEMENT(Inventory , Inv);
DEFINE_HOOK_REPLACEMENT(Dynamic   , Dyn);
DEFINE_HOOK_REPLACEMENT(TextDraw  , TD );
DEFINE_HOOK_REPLACEMENT(Update    , Upd);
DEFINE_HOOK_REPLACEMENT(Object    , Obj);
DEFINE_HOOK_REPLACEMENT(Command   , Cmd);

// Replaces the existing declarations.
enum E_HOOK_NAME_REPLACEMENT_DATA
{
    E_HOOK_NAME_REPLACEMENT_SHORT[4],
    E_HOOK_NAME_REPLACEMENT_LONG[16],
    E_HOOK_NAME_REPLACEMENT_MIN,
    E_HOOK_NAME_REPLACEMENT_LEN
}

static stock
    YSI_g_sReplacements[MAX_HOOK_REPLACEMENTS][E_HOOK_NAME_REPLACEMENT_DATA],
    YSI_g_sReplacePtr;

// New stuff.
stock _Hooks_AddReplacement(const longName[], const shortName[])
{
    // MAY need to strip spaces off the input strings, but I don't think so.
    if (YSI_g_sReplacePtr == MAX_HOOK_REPLACEMENTS)
    {
        P:E("Insufficient space in the replacements table.");
        return;
    }
    strcpy(YSI_g_sReplacements[YSI_g_sReplacePtr][E_HOOK_NAME_REPLACEMENT_SHORT], shortName, 4),
    strcpy(YSI_g_sReplacements[YSI_g_sReplacePtr][E_HOOK_NAME_REPLACEMENT_LONG] , longName , 16),
    YSI_g_sReplacements[YSI_g_sReplacePtr][E_HOOK_NAME_REPLACEMENT_MIN] = strlen(shortName),
    YSI_g_sReplacements[YSI_g_sReplacePtr][E_HOOK_NAME_REPLACEMENT_LEN] = strlen(longName),
    ++YSI_g_sReplacePtr;
}

public OnScriptInit()
{
    P:1("Hooks_OnScriptInit called");
    state _ALS : _ALS_go;
    // Get the replacements.
    new
        idx,
        ptr;
    // Loop over the redefinition functions and call them to have them call the
    // "_Hooks_AddReplacement" function above.  If we were being REALLY clever,
    // these functions could be removed from the public functions table
    // afterwards (there is already code in y_hooks for this) to reduce is size.
    while ((idx = AMX_GetPublicPointerPrefix(idx, ptr, _A<@_yH>)))
    {
        // From "amx\dynamic_call.inc" - check it is included in "y_hooks.inc".
        CallFunction(ptr);
    }
    Hooks_DoAllHooks();
    P:1("Hooks_OnScriptInit chain");
    // Dump the generated callbacks for debugging.
    //DisasmDump("YSI_TEST.asm");
    HookChain_OnScriptInit();
    P:1("Hooks_OnScriptInit end");
    return 1;
}

Then replace sizeof (YSI_g_sReplacements) with YSI_g_sReplacePtr in Hooks_MakeShortName and Hooks_MakeLongName.

from ysi-includes.

Ahmad45123 avatar Ahmad45123 commented on June 11, 2024

Thanks for the info, Y-Less.
I will try and implement it.. If I succeeded, Will open a pull request.

from ysi-includes.

Misiur avatar Misiur commented on June 11, 2024

Misiur@3ba984c closes this

from ysi-includes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.