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

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-07-2016 , 13:59   Re: New API and Syntax
Reply With Quote #811

It probably wouldn't matter for the former two functions (actually you may get compiler errors if function prototypes take pass-by-ref into account, which they probably do), but it may affect something if you omit it in the last case.
klippy is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 12-07-2016 , 14:20   Re: New API and Syntax
Reply With Quote #812

this looks little better
PHP Code:
stock bool ClearTimer(Handle hTimerbool bAutoClose false// there is no need for an ampersand
{
    if (
hTimer == null) return false//in new syntax 'null' used instead 'INVALID_HANDLE'
    
    
KillTimer(hTimerbAutoClose);
    
hTimer null;
    return 
true;

__________________
Grey83 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-07-2016 , 14:55   Re: New API and Syntax
Reply With Quote #813

There is a reason it's passed by reference - you are setting it to null, which will have no effect on the original handle unless it's passed by reference.
klippy is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 12-07-2016 , 15:23   Re: New API and Syntax
Reply With Quote #814

Quote:
Originally Posted by addons_zz View Post
it is just or enforce pass by reference than by value.
--> it is just to enforce pass by reference than by value.

Well until now I do not think I saw a language passing arrays by value, but it does not mean there are not.

Quote:
Originally Posted by abrandnewday View Post
What does the ampersand even mean when used like that?
You may use them to make functions return like 10 values at the same time, but instead of doing like on Matlab/Python:
PHP Code:
...
    [ 
value1value2value3value4, ... ] = functionTooMuch();
... 
You do in Pawn:
PHP Code:
...
    
int value1;
    
int value2;
    
int value3;
    
int value4;
    ...
    
functionTooMuchvalue1value2value3value4, ... );
...

void functionTooMuchint &value1int &value2int &value3int &value4, ... )
{
    ...

I am not saying to go out there creating functions like this, it is just in title of curiosity.


____________________________________

Update:

Note:
PHP Code:
...
    [ 
value1value2value3value4, ... ] = functionTooMuch();
... 
That is not a array when I do this on Matlab:
PHP Code:
...
    [ 
value1value2value3, ... ] = functionTooMuch();
    
printf"value1: %g, value2: %g, value3: %g, ..."value1value2value3, ... );
... 
value1 may be a string size 100, value 2 may be a struct with a struct, value 3 a float value, etc heterogeneous types.
It would not result in a array but in separate variables correctly defined. A function declaration for that would be:
PHP Code:
function [ value1value2value3value4, ... ] = functionTooMuch()

    
value1 "Hi";
    
value2 = { [1,2], "Hello!"3.21312e-10, [3.21312e-103.21312e-10] };
    
value3 etc.

end 
Sadly there is not the operator as & pass values reference on Matlab, but there is a return for multiple variables.
Otherwise Pawn where the return cannot return multiple values, but there is the operator & to allow pass by reference.
PHP Code:
...
    
int value1;
    
float value2;
    
float value3[3];
    ...
    
functionTooMuchvalue1value2value3, ... );

    
char buffer[512];
    
Format(buffersizeof(buffer), "value1: %d, value2: %f, value3: %f, ..."value1value2value3[0], ... );
...

void functionTooMuchint &value1float &value2flat[] value3, ... )
{
    
value1 4;
    
value2 0.0013;
    
value3 = {5.3463.32445.1545};

On both languages you can accomplish the same thing but on different ways.
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective

Last edited by addons_zz; 12-07-2016 at 16:59. Reason: update
addons_zz is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-07-2016 , 16:29   Re: New API and Syntax
Reply With Quote #815

Quote:
Originally Posted by addons_zz View Post
--> it is just to enforce pass by reference than by value.

Well until now I do not think I saw a language passing arrays by value, but it does not mean there are not.
Arrays in C and C++ (Well, C arrays in C++) are always passed around by reference. That's where Pawn got its feature from. Oh, you wrote by value. My bad.

Quote:
Originally Posted by addons_zz View Post
You may use them to make functions return like 10 values at the same time, but instead of doing like on Matlab/Python:
PHP Code:
...
    [ 
value1value2value3value4, ... ] = functionTooMuch();
... 
You do in Pawn:
PHP Code:
...
    
int value1;
    
int value2;
    
int value3;
    
int value4;
    ...
    
functionTooMuchvalue1value2value3value4, ... );
...

void functionTooMuchint &value1int &value2int &value3int &value4, ... )
{
    ...

I am not saying to go out there creating functions like this, it is just in title of curiosity.
You can return arrays in Pawn too, and do something similar to your first example. Not as pretty though.
PHP Code:
public void OnPluginStart()
{
    
int tooMuch[5];
    
tooMuch functionTooMuch();
}

int[] functionTooMuch()
{
    
int tooMuch[] = {12345};
    return 
tooMuch;


Last edited by klippy; 12-07-2016 at 16:30.
klippy is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 12-07-2016 , 16:44   Re: New API and Syntax
Reply With Quote #816

That ClearTimer stock should just be removed and replaced with proper usage of delete and TIMER_DATA_HNDL_CLOSE.

As written, it's a massive change in behaviour to make the handle param by-val, the entire point of that stock is that it clears the passed variable when it kills the timer.
__________________

Last edited by asherkin; 12-07-2016 at 16:45.
asherkin is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 12-07-2016 , 21:25   Re: New API and Syntax
Reply With Quote #817

Quote:
Originally Posted by abrandnewday View Post
Yeah, that's one thing I want to do while I do the conversion, fix up things that could be done potentially better. But I gotta say, in an "on-the-topic-of-new-syntax-as-a-whole" kind-of way: I am a huge fan of the new syntax. Compared to old syntax, I find it 10x simpler to do things like create menus/panels, even things I considered "expert-level" stuff like datapacks/stringmaps/keyvalues with old syntax, are infinitely easier for me to understand and code up in new syntax. It might also just be a case of me not really getting the "knack of it" until around the time new syntax was pushed. Even though I originally was anti-new syntax, I eventually just forced myself to learn new syntax, and to actually be able to code things up on my own instead of ripping other people's work apart. It could've been because I never really applied myself and tried to learn how to code when I first began learning to make plugins.

I'm also a huge fan of the new methodmap classes. I've said in another post on this forum somewhere that I would've loved to see the addition of more methodmap classes, for example; Entity, Client, Prop, PropDynamic, PropStatic. Come to find out from a wonderful user (I can't recall who, but thank you to that person) that VoiDeD has already worked his magic and created a set of transitional syntax helpers that create new methodmap classes such as CBasePlayer and CTFPlayer and others.

tl;dr love the new syntax, easier to work with.

i know i edit my posts too much, deal with it.

can a brother get user title change to "don't fucking quote me, i edit my posts too fucking much"
Strangely enough, everytime I use VoiDeD's helpers, my plugins begin glitching out.
__________________
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 12-07-2016 , 22:38   Re: New API and Syntax
Reply With Quote #818

Quote:
Originally Posted by abrandnewday View Post
In what way(s), if you don't mind me asking.
usually I inherit from CTFPlayer and the plugin bugs out in a way in which it pretty much ignores code in certain spots and then I go on a debugging spree.

Then I rewrite the same code completely removing the thelpers and the code acts completely normal and as intended with no code being ignored.

It's strange and it sucks because I really do like the source engine-style methodmaps but this issue alone stops me from using them more often in my code.
__________________
nergal is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 12-16-2016 , 18:03   Re: New API and Syntax
Reply With Quote #819

I'm trying to export natives in a lazy way by making an array of strings and an array of function pointers but the compiler is throwing errors at me concerning the func ptr array...

redefining the array type as "NativeCall" didn't work either.

as usual, the code...

PHP Code:
char szExportedNatives[][] = {
    
"VSH2Boss.VSH2Boss",
    
"VSH2Boss.userid.get",
    
"VSH2Boss.index.get",
    
"VSH2Boss.iQueue.get",
    
"VSH2Boss.iQueue.set",
    
"VSH2Boss.iKills.get",
    
"VSH2Boss.iKills.set",
    
"VSH2Boss.iHits.get",
    
"VSH2Boss.iHits.set",
    
"VSH2Boss.iLives.get",
    
"VSH2Boss.iLives.set",
    
"VSH2Boss.iState.get",
    
"VSH2Boss.iState.set"
};

Function 
funcNatives[] = {
    
Native_VSH2BossInstance,
    
Native_getBossUserIdNative_getBossIndex,
    
Native_getQueueNative_setQueue,
    
Native_getPresetBossNative_setPresetBoss,
    
Native_getKillsNative_setKills,
    
Native_getHitsNative_setHits,
    
Native_getLivesNative_setLives,
    
Native_getBossStateNative_setBossState
};

public 
APLRes AskPluginLoad2(Handle myselfbool latechar[] errorint err_max)
{
    for (
int i=i<sizeof(funcNatives) ; ++i) {
        
CreateNative(szExportedNatives[i], funcNatives[i]);
        
MarkNativeAsOptional(szExportedNatives[i]);
    }

    
RegPluginLibrary("VsSaxtonHale2");

    return 
APLRes_Success;

This is the warning:

Code:
Compiling vsh2.sp ...
SourcePawn Compiler 1.8.0.5951
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2015 AlliedModders LLC

vsh2.sp(1146) : error 008: must be a constant expression; assumed zero (1146 is the Native_VSH2BossInstance in the array)
vsh2.sp(1158) : error 163: indeterminate array size in "sizeof" expression (symbol "funcNatives")

2 Errors.
__________________

Last edited by nergal; 12-16-2016 at 18:09.
nergal is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-16-2016 , 21:13   Re: New API and Syntax
Reply With Quote #820

Doing
PHP Code:
const NativeCall nat Native_VSH2BossInstance
throws
Code:
error 008: must be a constant expression; assumed zero
which would mean that the compiler doesn't see functions as compile-time constants for whatever reason (maybe developers can explain?). So it looks like you can't reference functions in an array.
klippy is offline
Reply



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 01:33.


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