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

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-14-2014 , 02:42   Re: New API and Syntax
Reply With Quote #251

Quote:
Originally Posted by BAILOPAN View Post
Hrm... 1.7 has the "any" type.
Yes, my mistake. I meant to say transitional doesn't:

Quote:
Originally Posted by dvander
I don't have concrete plans yet, but basically the any keyword will have to be deprecated. I tried to do that in 1.7 but ran out of time, so it'll have to be for 1.8.
A potential replacement is discussed further.

Quote:
Originally Posted by BAILOPAN View Post
Not sure where that misconception came from as I don't think I mentioned removing it or it being a reason for not doing something.
In addition to mentioning "any" was being deprecated in 1.8:

Quote:
Originally Posted by dvander
...passing opaque values is not compatible post-transitional-syntax, since there is no way to track the liveness of the value.
This quote came from the same pull request as earlier. Said pull request saved data very similarly to the way the Timer code does... you could say it was copied almost verbatim from the Timer code.

Like timer's data argument, it used the any tag to assign data during the Menu's creation and had a special flag to mark it as a Handle that should be closed when CloseHandle was called on the menu's Handle.

The above pull request was closed as it was made clear it wasn't going to be added to SM.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
BAILOPAN
Join Date: Jan 2004
Old 12-14-2014 , 03:13   Re: New API and Syntax
Reply With Quote #252

Transitional syntax has the any type. As part of the transitional specification (which I hope to have ready soon), "any" is basically an untyped opaque cell with implicit coercion to/from primitive types and enums.

The problem is that "any" is not well-typed in C++. As long as its surface area is restricted to natives, gradually porting everything in the future should be doable. Baking it into the C++ API makes things difficult down the road though.
__________________
egg

Last edited by BAILOPAN; 12-14-2014 at 03:18.
BAILOPAN is offline
BAILOPAN
Join Date: Jan 2004
Old 12-14-2014 , 05:07   Re: New API and Syntax
Reply With Quote #253

One more minor change. It is now an error to coerce "any[]" to/from "char[]". I'm a little horrified this was possible . From now on, "any[]" will only coerce to/from 32-bit storage classes. The same will hold true for references. "any" to/from "char" (without any reference/array types involved) will still work.
__________________
egg

Last edited by BAILOPAN; 12-14-2014 at 05:08.
BAILOPAN is offline
API
Veteran Member
Join Date: May 2006
Old 12-15-2014 , 11:15   Re: New API and Syntax
Reply With Quote #254

Question: How am I supposed to store Function values into ADT arrays? I am getting this error:
Code:
error 130: cannot coerce functions to values
Trying to do this:
Code:
PushArrayCell(s_TimerData, p_CompleteCallback);
I noticed there is GetNativeFunction() for natives, but I don't see anything for ADT arrays. Also, what exactly are functions if they can not be represented as cells? AFAIK, they are just IDs, correct?

EDIT: Just as a note, I think a possible workaround for this would be to store the function as a string. That is, as long as GetFunctionByName() still works
EDIT2: Just to confirm, I am able to cheat around this using GetFunctionByName()
__________________

Last edited by API; 12-15-2014 at 11:41.
API is offline
Send a message via AIM to API
BAILOPAN
Join Date: Jan 2004
Old 12-15-2014 , 14:22   Re: New API and Syntax
Reply With Quote #255

@pimpinjuice - Yup, that's a fine workaround. That error was needed to start ditching semantics that prevent us from implementing anonymous functions.
__________________
egg
BAILOPAN is offline
API
Veteran Member
Join Date: May 2006
Old 12-15-2014 , 17:02   Re: New API and Syntax
Reply With Quote #256

Thanks. Sounds good, can't wait to see what the future holds for the language.
__________________
API is offline
Send a message via AIM to API
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-16-2014 , 11:28   Re: New API and Syntax
Reply With Quote #257

Found a bug in the new API syntax while working on mapchooser.sp.

Here's a typedef from menus.inc:

Code:
/**
 * Callback for when a vote has ended and results are available.
 *
 * @param menu				The menu being voted on.
 * @param num_votes			Number of votes tallied in total.
 * @param num_clients		Number of clients who could vote.
 * @param client_info		Array of clients.  Use VOTEINFO_CLIENT_ defines.
 * @param num_items			Number of unique items that were selected.
 * @param item_info			Array of items, sorted by count.  Use VOTEINFO_ITEM
 *							defines.
 */
typedef VoteHandler = function void (
  Menu menu,
  int num_votes, 
  int num_clients,
  const int client_info[][2], 
  int num_items,
  const int item_info[][2]
);
You can't actually have a function with this signature in the new syntax:

Code:
public void Handler_MapVoteFinished(Menu menu,
						   int num_votes, 
						   int num_clients,
						   const int client_info[][2], 
						   int num_items,
						   const int item_info[][2])
spits out error 159: brackets after variable name indicate a fixed-size array, but size could not be determined - either specify sizes, an array initializer, or use dynamic syntax (such as 'char[] x')

Code:
public void Handler_MapVoteFinished(Menu menu,
						   int num_votes, 
						   int num_clients,
						   const int[][2] client_info, 
						   int num_items,
						   const int[][2] item_info)
spits out error 140: new-style array types cannot specify dimension sizes as part of their type

Code:
public void Handler_MapVoteFinished(Menu menu,
						   int num_votes, 
						   int num_clients,
						   const int client_info[][], 
						   int num_items,
						   const int item_info[][])
tosses both error 100: function prototypes do not match and error 159: brackets after variable name indicate a fixed-size array, but size could not be determined - either specify sizes, an array initializer, or use dynamic syntax (such as 'char[] x')

and

Code:
public void Handler_MapVoteFinished(Menu menu,
						   int num_votes, 
						   int num_clients,
						   const int[][] client_info, 
						   int num_items,
						   const int[][] item_info)
spit out error 100: function prototypes do not match

To be honest, I'm not sure how you can fix this without breaking plugins... short of updating the compiler.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-16-2014 at 14:19.
Powerlord is offline
BAILOPAN
Join Date: Jan 2004
Old 12-16-2014 , 14:19   Re: New API and Syntax
Reply With Quote #258

I guess it'll need to be in a typeset.
__________________
egg
BAILOPAN is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-16-2014 , 16:14   Re: New API and Syntax
Reply With Quote #259

Quote:
Originally Posted by BAILOPAN View Post
I guess it'll need to be in a typeset.
Wasn't aware typesets could contain multiple functions with the same number and types1 of arguments.

However, the compiler isn't complaining, so... pull request!

1 Assuming fixed and dynamic arrays are considered to be the same type, which they may not be in this instance.

Edit: While I'm at it, lets Pull Request the conversions I did on some of the core plugins, too. Better to do that now and do further changes to add new features in a separate branch.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-16-2014 at 16:32.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-16-2014 , 17:27   Re: New API and Syntax
Reply With Quote #260

OK, BAILOPAN merged that pull request (well, the first one). So as of 1.7-git5094, now you can do this in New API style:

Code:
public void Handler_MapVoteFinished(Menu menu,
						   int num_votes, 
						   int num_clients,
						   const int[][] client_info, 
						   int num_items,
						   const int[][] item_info)
and it doesn't toss errors.

Note that this sample was pulled from mapchooser.sp.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 12-16-2014 at 17:29.
Powerlord is offline
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

Forum Jump


All times are GMT -4. The time now is 00:41.


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