Giter Club home page Giter Club logo

Comments (2)

Daniel-Cortez avatar Daniel-Cortez commented on August 17, 2024

ALS7 hooking method

It's called ALS4, not 7.

In Pawn 3.2 it was possible to "hook" a function using a compiler bug.

Besides 3.2 it works in Pawn 4.0 as well. The behavior has changed in commit 6de1822 to be precise, so ALS4 doesn't work in the development version, but the 4.0 release is unaffected.

Anyway, here's an example of how it worked before 6de1822:

#include <console>


main()
{
    print("This is a message from the main() hook #1.\n");
#if defined hook1_main
    hook1_main();
#endif
    return 1;
}
#if defined _ALS_main
    #undef main
#else
    #define _ALS_main
#endif
#define main hook1_main
forward hook1_main();

main()
{
    print("This is a message from the main() hook #2.\n");
#if defined hook2_main
    hook2_main();
#endif
    return 1;
}
#if defined _ALS_main
    #undef main
#else
    #define _ALS_main
#endif
#define main hook2_main
forward hook2_main();

main()
{
    print("This is a message from the main() hook #3.\n");
#if defined hook3_main
    hook3_main();
#endif
    return 1;
}
#if defined _ALS_main
    #undef main
#else
    #define _ALS_main
#endif
#define main hook3_main
forward hook3_main();


main()
{
    print("main()\n");
}

Output:

This is a message from the main() hook #1.
This is a message from the main() hook #2.
This is a message from the main() hook #3.
main()

After that breaking commit the above example doesn't work. The compiler ends up in an endless loop repeatedly printing the following messages:

test.p(39) : warning 208: function "hook3_main" is used before definition, a forward declaration is recommended
test.p(23) : warning 208: function "hook2_main" is used before definition, a forward declaration is recommended
test.p(7) : warning 208: function "hook1_main" is used before definition, a forward declaration is recommended
test.p(39) : warning 208: function "hook3_main" is used before definition, a forward declaration is recommended
test.p(23) : warning 208: function "hook2_main" is used before definition, a forward declaration is recommended
test.p(7) : warning 208: function "hook1_main" is used before definition, a forward declaration is recommended
...

It would be great if the old behavior could have been brought back.

from pawn.

compuphase avatar compuphase commented on August 17, 2024

Corrected in commit 9895412.
The warnings for the three hook functions are still being output, but the compiler does not fall in an endless loop anymore.

from pawn.

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.