SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 16/10/2018, 12:01 PM   #1
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 336
Reputation: 255
Default Long Function Names

Purpose
Normally, Pawn function names cannot exceed 31 characters. This is a limitation of both the compiler and the execution engine, which discards AMX programs with longer function names. This plugin removes this limitation of the AMX engine and allows scripts with longer names (of native functions, public functions, and public variables) to execute normally, without modifications to the names themselves. Other scripts will be unaffected by this plugin.

Other plugins may use this plugin to register natives or call public functions with long names. No special API is required to make this work, since the majority of the AMX API can work with any length. However, you should always use amx_NameLength to retrieve the maximum length used by the script.

You will need a compiler supporting longer function names. Check out my fork which increases the length to 63.

Please note that some Pawn libraries may not work properly with longer identifiers. In this case, you either need to configure them in some way to increase the limit, or contact the author.

Example
pawn Code:
#include <a_samp>

forward VeryLongPublicFunctionNameExceeding31Characters();
public VeryLongPublicFunctionNameExceeding31Characters()
{
    print("hello!");
}

public OnFilterScriptInit()
{
    CallLocalFunction("VeryLongPublicFunctionNameExceeding31Characters", "");
}
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode

Last edited by IllidanS4; 17/10/2018 at 02:32 PM.
IllidanS4 is offline   Reply With Quote
Old 16/10/2018, 01:26 PM   #2
KinderClans
Banned
 
Join Date: May 2018
Location: Italy
Posts: 726
Reputation: 43
Default Re: Long Function Names

If there is a limit of 31 characters, there must be a reason, no?

Also i don't like long function names, they're useless and confusing. But that's my opinion.

Someone else will find this useful. Good job.
KinderClans is offline   Reply With Quote
Old 16/10/2018, 02:13 PM   #3
IllidanS4
Huge Clucker
 
IllidanS4's Avatar
 
Join Date: Feb 2013
Posts: 336
Reputation: 255
Default Re: Long Function Names

Quote:
Originally Posted by KinderClans View Post
If there is a limit of 31 characters, there must be a reason, no?

Also i don't like long function names, they're useless and confusing. But that's my opinion.

Someone else will find this useful. Good job.
The limit is completely arbitrary; in older versions of AMX, the size of a record was fixed, but now all names are located in the name table which is just a pool of variable-length strings. The only functions in the API that depend on on the limit are amx_Init, amx_Cleanup, amx_FindNative, amx_FindPublic, and amx_FindPubVar. All of these functions except for amx_Cleanup are hooked by this plugin, removing the dependency.

The limit might have been useful for C programmers in times where variable-length arrays needed explicit destruction, so they could simply allocate 32 characters on the stack, without worrying about the deallocation, and know that all names fit inside, but since there is amx_NameLength (which you should use according to the GCA), you can dynamically allocate the buffer in C++ (or use alloca) based on the length.

In my opinion, arbitrary bounds based on no real limitations are bad, but there might be another reason for this. Certain mechanisms that work with already existing names might need to "expand" them a little bit (mangling for example), so if there is a function SetPlayerChatBubbleForPlayer (28 characters), turning it into SetPlayerChatBubbleForPlayer@6uuSufi (36 characters) is already over the limit.

You could argue that using abbreviated forms instead of the componenets fixes this (SetPlChBubbleFPl), but I'd rather not have my code turned into WINAPI, thank you.
__________________
PawnPlus
YSF
Yet Another Lua Plugin
Long Function Names
 i_quat.inc 


kingsofsa.cz:8888 running Cinematic Mode
IllidanS4 is offline   Reply With Quote
Old 16/10/2018, 03:13 PM   #4
GangstaSunny.
Huge Clucker
 
GangstaSunny.'s Avatar
 
Join Date: Apr 2010
Location: Hamburg - Germany
Posts: 248
Reputation: 34
Default Re: Long Function Names

Yap, the most the like to "who is using over 31 characters?!".

I meet this a few times.
+rep, nice work dude.
GangstaSunny. is offline   Reply With Quote
Old 16/10/2018, 08:36 PM   #6
Peek
Little Clucker
 
Join Date: Dec 2013
Posts: 9
Reputation: 7
Default Re: Long Function Names

Thanks that will definitely come in handy, I happen to be looking for something like this yesterday.
Peek is offline   Reply With Quote
Old 16/10/2018, 09:44 PM   #7
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,751
Reputation: 836
Default Re: Long Function Names

Now i no longer have to create abbreviations while hooking function names like OnPlayerClickPlayerTextDraw etc.

++rep;
__________________

Follow me on Github: Follow me on Spotify: Donate on Paypal:

Gammix is offline   Reply With Quote
Old 16/10/2018, 09:50 PM   #8
Whyd
Huge Clucker
 
Whyd's Avatar
 
Join Date: Sep 2012
Location: /
Posts: 432
Reputation: 30
Default Re: Long Function Names

Just what i needed, genius!
Whyd is offline   Reply With Quote
Old 27/10/2018, 01:12 PM   #9
Spoookymon
Little Clucker
 
Join Date: Apr 2017
Posts: 47
Reputation: 2
Default Re: Long Function Names

(h) it.
Is it's possible to increase include file limit, what i mean is that it's limited to 30 caharcters.

Ex:
(Works)
#include "A/BC/ZXC/Asdfghjklzx/Abc1.pwn"
#include "A/BC/ZXC/Asdfghjklzx/Abc2.pwn"

(Abcd2.pwn will not be included)
#include "A/BC/ZXC/Asdfghjklzx/Abcd1.pwn"
#include "A/BC/ZXC/Asdfghjklzx/Abcd2.pwn"
Spoookymon is offline   Reply With Quote
Old 27/10/2018, 01:43 PM   #10
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,178
Reputation: 384
Default Re: Long Function Names

Quote:
Originally Posted by Gammix View Post
Now i no longer have to create abbreviations while hooking function names like OnPlayerClickPlayerTextDraw etc.

++rep;
Exactly, good job!
__________________
Quote:
Originally Posted by Andy
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link


RogueDrifter is offline   Reply With Quote
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Long Function OnGameModeInit Kyle Scripting Help 1 09/05/2012 05:14 PM
About long names saving. KreeDz Help Archive 2 07/06/2011 05:34 PM
Function to hide names? Antonio [G-RP] Help Archive 4 05/06/2010 03:56 AM
[HELP] Long and short names. kukars22 Help Archive 4 03/12/2009 04:51 AM


All times are GMT. The time now is 08:53 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.