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

New API and Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 01-28-2015 , 23:08   Re: New API and Syntax
Reply With Quote #321

Perfect. Thanks!
Potato Uno is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-03-2015 , 08:36   Re: New API and Syntax
Reply With Quote #322

I recently found out two incompatibilities with old code and thought I let you know about it. You can use this and this to check yourself.
PHP Code:
stock MyFunction(clientMyEnum:data)
{
}

enum MyEnum
{
}; 
It compiles if the enum is defined before it's used.

PHP Code:
public OnPluginStart()
{
    
SomeFunc(10);
}

SomeFunc(size)
{
    new 
String:buffer[size][1024];
    new 
size2 sizeof(buffer[]);
    
#pragma unused size2

It compiles when size is changed to a static number, this might help in finding out what's causing it.
__________________

Last edited by Impact123; 02-03-2015 at 08:56.
Impact123 is offline
BAILOPAN
Join Date: Jan 2004
Old 02-03-2015 , 15:54   Re: New API and Syntax
Reply With Quote #323

@Impact123 - Thanks, I will take a look at the first bug. The second example will probably not be fixed (at least, not for 1.7). New-style syntax does not support partial fixed-length arrays, that is, a nested array either contains all fixed-length arrays or all indeterminate arrays. The new behavior of sizeof reflects that. The intent is to have code like,

PHP Code:
static const int kBufferSize 1024;

void SomeFunc(int size)
{
    
char buffer[size][kBufferSize];

__________________
egg
BAILOPAN is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-03-2015 , 20:26   Re: New API and Syntax
Reply With Quote #324

Here's another thing i found so far.
PHP Code:
stock static SomeStaticStock()
{

It compiles if the static keyword is omitted, or, as asherkin noted below, the order is switched.

Edit: This can be ignored, see here.
__________________

Last edited by Impact123; 02-03-2015 at 20:56.
Impact123 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-03-2015 , 20:33   Re: New API and Syntax
Reply With Quote #325

I believe static needs to be before stock.
__________________
asherkin is offline
nergal
Veteran Member
Join Date: Apr 2012
Old 02-03-2015 , 20:52   Re: New API and Syntax
Reply With Quote #326

may i ask why there's no official IDE for sourcepawn? ;3
__________________
nergal is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 02-03-2015 , 20:54   Re: New API and Syntax
Reply With Quote #327

@asherkin
Yes and no. I searched a little bit and found this commit that seems to have fixed it.
I'm an idiot for not testing this with the newest compiler.
__________________

Last edited by Impact123; 02-03-2015 at 21:13.
Impact123 is offline
BAILOPAN
Join Date: Jan 2004
Old 02-03-2015 , 21:32   Re: New API and Syntax
Reply With Quote #328

The *intended* grammar is "static" "stock", I had to cave in to older plugins unfortunately.

Evidence suggests that a good IDE takes a few hundred million dollars and about 10 years of development. I checked under my couch and couldn't find that much money. I'll check under the cushions a second time, but until then there's lots of very good editors out there (Sublime is popular).
__________________
egg
BAILOPAN is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 02-04-2015 , 11:49   Re: New API and Syntax
Reply With Quote #329

So I stumbled across the feature that you can chain methodmaps (see below).

Spoiler


I think this would be useful to implement in some of the methodmaps that come with sourcemod, such as StringMap. Of course, this would only work with functions where return value isn't needed.

Here would be an example:
Spoiler


This wouldn't be difficult to change in the current methodmaps for at least the functions that would normally return void, or even some like StringMap.GetValue() that returns a boolean. It could be modified to support default values like KeyValues.GetNum().

If not possible, I could even write up some extended methodmaps to apply this functionality under types (tags? I don't know the term here) like StringMapEx.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
BAILOPAN
Join Date: Jan 2004
Old 02-04-2015 , 12:29   Re: New API and Syntax
Reply With Quote #330

Yup, the accessor grammar is recursive so you can use the result of an accessor as an accessor.

SQL query building or something would be more amenable to this treatment - StringMap doesn't strike me as a good candidate. Chaining isn't to reduce keystrokes, it's to make a complex, compound operation *more* clear than it would have been otherwise. For example,

PHP Code:
  map.Set("a"5)
  
map.Set("b"6
Is a lot more clear (and maintainable) than,

PHP Code:
  map.Set("a"5).Set("b"6
For other APIs this is not true. Imagine an API like,

PHP Code:
  builder SQL.Select("first_name""last_name")
  
builder.From("table_a")
  
builder.Join("table_b")
  
builder.On("a_id = b_id")
  
builder.Where("a_id > 500"
If we chain it...

PHP Code:
  builder SQL.Select("first_name""last_name").
    
From("table_a").
    
Join("table_b").On("a_id = b_id").
    
Where("a_id > 500"
Now chaining is a huge improvement. A bunch of directly related, order-dependent operations are formatted to look exactly like the operation they perform.
__________________
egg

Last edited by BAILOPAN; 02-04-2015 at 12:34.
BAILOPAN 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 19:33.


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