compuphase / pawn

Pawn is a quick and small scripting language that requires few resources.

Home Page:http://www.compuphase.com/pawn/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request: standalone references?

assyrianic opened this issue · comments

Is it alright that I request Pawn to have standalone references like C++ does?

new i = 5;
new &p = i;
p = 9; // i is now 9

Perhaps denote it by giving it a different operator?
modified example above

new i = 5;
new @p = i;
p = 9; // i is now 9

Same example above but with floating point.

new float:f = 5.02;
new &float:p = f;
p = 3.14; // f is now 3.14

The @p example won't work - @ is already a valid symbol character in PAWN (though rarely used outside of low-level libraries in my experience), so @p is a valid variable now. Also, a function with @ as the first character of its name is public even without the public keyword:

@MyPublic();

@MyPublic()
{
    print("hi");
}

main()
{
    CallLocalFunction("@MyPublic", ""); // Works.
}

Note that this is not quite a replacement for public because it remains part of the name, you can't do @ MyPublic and then just refer to the function as MyPublic.

The & operator on the other hand already has precedence for this in that it is the syntax when declaring functions, so a different syntax would probably be more confusing. (Side note, I also used & for some libraries that can take the address of a function in the same way).

hmmm, how about $ as an alternative token for standalone references?
Example:

new i = 5;
new $p = i;
p = 2; // i == 2

I don't believe the $ is used is it?

No, but still why not just & - I think that would cause far less confusion as it already means that:

MyFunc(&a, &b)
{
    a = 7;
    printf("%d", b); // Prints 7.
}

main()
{
    new var = 11;
    MyFunc(var, var);
}