Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Extension methods C# like #761

Open
TheByKotik opened this issue Feb 4, 2022 · 1 comment
Open

[Feature Request] Extension methods C# like #761

TheByKotik opened this issue Feb 4, 2022 · 1 comment

Comments

@TheByKotik
Copy link

If you know about extension methods in C#, you know is good layer of abstraction.
As example SourceMod have this function:

/**
 * Converts an integer to a string.
 *
 * @param num           Integer to convert.
 * @param str           Buffer to store string in.
 * @param maxlength     Maximum length of string buffer.
 * @return              Number of cells written to buffer.
 */
native int IntToString(int num, char[] str, int maxlength);

But this can be simplify to:

// Syntax below is not real syntax, just example how it may look

// int.inc
native int ToString (char[] szBuffer, const int iSize, const int iBase = 10) extend int;
// plugin.sp
char[32] buffer;

1300.ToString( buffer, sizeof buffer );

int i = 7777;
i.ToString( buffer, sizeof buffer, 2 );
@dvander
Copy link
Member

dvander commented Feb 4, 2022

I like this feature in C# and I think it's some clever syntactic sugar. But we're not ready for this in spcomp. Even in the fancy new compiler, it's fundamentally based on tagged cells, and still has no formal notion of types. That makes it harder to implement features like this, and I don't want to add too many kludges around name lookups.

Source-only plugins is probably a blocker for this, but certainly it's a 1.12 feature either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants