Raised This Month: $32 Target: $400
 8% 

Returning function through native


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-08-2017 , 18:01   Returning function through native
Reply With Quote #1

Currently when you return a Function type through a native you get a warning about coercing functions and ints.

Code:
public int SomeNative()
{
   return view_as<int>(INVALID_FUNCTION);
}
Is there any way to avoid this.

I tried a ref arg but the native set cell also triggers the warning.
__________________

Last edited by Neuro Toxin; 08-08-2017 at 18:07.
Neuro Toxin is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-08-2017 , 21:05   Re: Returning function through native
Reply With Quote #2

PHP Code:
public Function SomeNative()
{
    return 
INVALID_FUNCTION;

headline is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 08-08-2017 , 21:57   Re: Returning function through native
Reply With Quote #3

Quote:
Originally Posted by Headline View Post
PHP Code:
public Function SomeNative()
{
    return 
INVALID_FUNCTION;

Natives need to have return type of int.


@Neuro Toxin
A hack-around could be using datapacks.
__________________

Last edited by Deathknife; 08-08-2017 at 21:58.
Deathknife is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 08-08-2017 , 22:26   Re: Returning function through native
Reply With Quote #4

Idk how I read over that lol

You can't pass Functions through natives. What are you trying to accomplish by doing that?

Last edited by headline; 08-08-2017 at 22:28.
headline is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-09-2017 , 01:39   Re: Returning function through native
Reply With Quote #5

I can parse Functions natives through natives.

I need to support Function in Dynamic.

Code:
	public Function GetFunction(const char[] membername)
	{
		return Dynamic_GetFunction(this, membername);
	}

	public DynamicOffset SetFunction(const char[] membername, Function value)
	{
		return Dynamic_SetFunction(this, membername, value);
	}

	public Function GetFunctionByOffset(DynamicOffset offset)
	{
		return Dynamic_GetFunctionByOffset(this, offset);
	}

	public void SetFunctionByOffset(DynamicOffset offset, Function value)
	{
		Dynamic_SetFunctionByOffset(this, offset, value);
	}

	public int PushFunction(Function value, const char[] name="")
	{
		return Dynamic_PushFunction(this, value, name);
	}

	public Function GetFunctionByIndex(int index)
	{
		return Dynamic_GetFunctionByIndex(this, index);
	}
I want to remove the warning.

I need to iterate callbacks.
__________________

Last edited by Neuro Toxin; 08-09-2017 at 01:40.
Neuro Toxin is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-09-2017 , 04:11   Re: Returning function through native
Reply With Quote #6

No, this is not currently possible - and the warning will turn into an error in the future.

I am unsure what the path forward here is, fakenatives are in a bit of a weird position.
__________________
asherkin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-09-2017 , 05:30   Re: Returning function through native
Reply With Quote #7

Maybe some native param methods for Function would do the job.
__________________
Neuro Toxin 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 05:15.


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