View Single Post
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 05-30-2016 , 07:36   Re: Returning null handle in native
Reply With Quote #10

Quote:
Originally Posted by Tirant View Post
It's certainly an interesting behavior, unique to the typelessness of SourcePawn and how the native API works. In other languages, null could not be used in this context (doesn't make sense to cast a null pointer to something else), but in this case where a native should be able to return null but can't because null isn't castable.
That's not really true. You can look at it from the C# perspective: you can null reference types, but not value types. Here in the new SourcePawn API, you can look at integers, floats, characters and booleans (and arrays?) as value types, and handles as reference types. When you assign one handle to another, you are not copying the object but rather copying the reference, so both handles point to the same object.
In my opinion, it's understandable why null can't be cast to these primitive types.

EDIT:
@SM Devs, could we have something like the following?
PHP Code:
typeset NativeCall
{
    function 
int(Handle pluginint numParams),
    function 
Handle(Handle pluginint numParams)
}; 
So people can choose to either return a value of primitive type or of Handle type. Handles are just cells(ints) after all.

Last edited by klippy; 05-30-2016 at 08:18.
klippy is offline