Comments (14)
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.
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.
Zeex same error compiler too ...
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
hook OnPlayerEnterRaceCheckpoint(playerid)
{
SendClientMessage(playerid, -1, "You entered to raceCheckPoint");
}
from ysi-includes.
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.
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.
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.
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.
It WILL work. Take a look here, those replacements are clearly defined.
from ysi-includes.
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.
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.
Note: maddinat0r et. al. replied while I was writing this, so the first bit was from before they posted...
Have you tried?
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:
-
@yH_
This seems like the most obvious candidate for shortening, but it serves two purposes:- The prefix (almost) removes any chance of a naming collision with user code. Many YSI generated functions start with a combination of
@
,_
,y
, andX
whereX
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 thepublic
keyword in that case), static ones usually start with_
, others arey_@X
or similar. @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.
- The prefix (almost) removes any chance of a naming collision with user code. Many YSI generated functions start with a combination of
-
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.
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.
Thanks for the info, Y-Less.
I will try and implement it.. If I succeeded, Will open a pull request.
from ysi-includes.
Misiur@3ba984c closes this
from ysi-includes.
Related Issues (20)
- I found a problem in y_inline_bcrypt. HOT 2
- YSI_Coding\y_timers\..\..\YSI_Core\y_core\y_scriptinit_impl.inc(434) : fatal error 111: user error: defined OnScriptInit HOT 1
- va_args stopped working after update HOT 6
- What does callbackfix.amx do? HOT 1
- (error) undefined symbol "Dialog_ShowPlayerNative HOT 2
- Error when using y_commands HOT 1
- Error when updating YSI HOT 2
- Long callback execution detected (hang or performance issue) or DDoS Attack HOT 1
- Issues with using y_iterator HOT 1
- y_inline_timers calling the timer function twice HOT 1
- AMX Size HOT 1
- Can't include y_races
- error complil HOT 1
- Y_Hooks not called with 3.10.11 Compiler and Open.MP HOT 2
- y_functional_funcs.inc(1154) : error 017: undefined symbol "j"
- bcrypt_delete File or function is not found since last YSI Update. HOT 4
- \pawno\include\YSI_Data\y_foreach\y_foreach_entry.inc(137) : fatal error 111: user error: Old <foreach.inc> found - delete it.
- Unable to compile with y_zonenames and y_races
- pawn.cc crashes when i use the last version of ysi includes
- helpp me YSI HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ysi-includes.