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

Creating natives, new syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-07-2015 , 00:08   Creating natives, new syntax
Reply With Quote #1

So this is what I had before:

Spoiler


I turned it into this:

PHP Code:
public APLRes AskPluginLoad2(Handle hMyselfbool bLatechar[] strErrorint Err_Max) {
    
CreateNative("someNative"Native_SomeNative);
}

public 
bool Native_SomeNative(Handle pluginint numParams) {
    
//stuff
    
return someBool;

but that gives this compiler error:
Code:
error 100: function prototypes do not match
Replacing the "public bool" with "public int" seems to be the only way to compile without errors, but it bugs me since the native is returning a bool, not an int. Is this the correct way to "fix" this issue? Is that what this page is indicating?
__________________

Last edited by ddhoward; 06-07-2015 at 00:28.
ddhoward is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-07-2015 , 03:42   Re: Creating natives, new syntax
Reply With Quote #2

CreateNative require callback NativeCall type, It need return int, in your code it return bool.
PHP Code:
public bool Native_SomeNative(Handle pluginint numParams) { 
replace to
PHP Code:
public int Native_SomeNative(Handle pluginint numParams) { 
Kailo is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-07-2015 , 17:40   Re: Creating natives, new syntax
Reply With Quote #3

Natives always return an int.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-07-2015 , 21:51   Re: Creating natives, new syntax
Reply With Quote #4

Just to clarify, can I put " native bool:someNative(); " in the inc, and do "return someBool;" in the native's body? Or is there a more "proper" way to do it?
__________________

Last edited by ddhoward; 06-07-2015 at 21:52.
ddhoward is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 06-07-2015 , 23:13   Re: Creating natives, new syntax
Reply With Quote #5

There is nothing more proper except for maybe adding a view_as<bool>

Last edited by Mathias.; 06-07-2015 at 23:13.
Mathias. is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 06-08-2015 , 02:39   Re: Creating natives, new syntax
Reply With Quote #6

You have to remove the tag im the native call, return _:
In your inc you can use types.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 06-08-2015 , 04:12   Re: Creating natives, new syntax
Reply With Quote #7

Quote:
Originally Posted by friagram View Post
You have to remove the tag im the native call, return _:
In your inc you can use types.
Quote:
warning 240: '_:' is an old-style tag operation; use view_as<int>(expression) instead
__________________
ddhoward is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 06-08-2015 , 07:36   Re: Creating natives, new syntax
Reply With Quote #8

Your question is answer!
replace
PHP Code:
_:var 
to
PHP Code:
view_as<int>(var) 
Kailo is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 06-08-2015 , 08:04   Re: Creating natives, new syntax
Reply With Quote #9

view_as<> was created to deprecate the retagging system(ex: _:var; bool:var).
PHP Code:
view_as<int>(somebool//Same as doing: _:somebool 
__________________

Last edited by WildCard65; 06-08-2015 at 08:04.
WildCard65 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 07:42.


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