New API and Syntax
Hi, everyone! SourceMod 1.7 development is underway, and I'm excited to announce that SourcePawn is undergoing radical changes. The API is becoming object-oriented, and the syntax is becoming more C#/Java-like. All of the changes are opt-in, and old scripts will continue to compile.
Without further ado... Motivation Pawn is derived from "Small C", which was made in 1984. It has a number of severe syntactic and semantic flaws compared to modern languages, and it's become quite painful to use. All of its problems can be ultimately blamed on the tag system. The tag system erases type information, which prevents us from implementing garbage collection, which prevents us from implementing better datastructures, true arrays, true strings, objects, and lambda functions. Our ultimate goal is for Pawn to become a "C# Lite", but getting there is difficult: we have to rewrite the compiler, the JIT, and our entire API. That's an insane amount of work, so we're taking a new approach by introducing transitional syntax, transitional APIs, and a transitional type system. Hopefully we're killing two birds with one stone: we'll make a major dent in the tag system, put foundations in place for our future API, and provide some major short-term improvements to Pawn usability. Syntax Changes As of SourcePawn 1.7, there is a new preferred way of declaring variables and function signatures. Fans of Java/C# will find it much more familiar. Here are some before and after examples: PHP Code:
The new style is important for a few reasons. First, it visually removes the concept of tags. Second, it formalizes int as an actual type, replacing "cells" (which were part of the tag system). Third, it formalizes void, which will make it easier to implement modules in the future. Finally, it gives us a chance to replace old type names with better ones. For example, String is not only misnamed, but will be confusing when we have a true string type. The new type names are int, float, char, void, and object, and are only available in new-style declarations. They cannot be used as tags. Methodmaps SourcePawn 1.7 has a new feature called "methodmaps" for creating object-oriented APIs. Most users will not be creating their own methodmaps, so I defer to the full documentation for the gory details. The idea is that you can now attach functions to tags. For example: PHP Code:
PHP Code:
Object-Oriented API We've ported adt_trie, adt_array, and menus. For example, creating a simple menu beforehand might have looked something like this: PHP Code:
PHP Code:
Most of our API has not yet been transitioned to methodmaps. I am hoping we'll be able to release 1.7 with a full object-oriented API, so if you want to use something in the includes that has not yet been ported, feel free to submit a patch! We may also consider an automatic porting tool for plugins once enough of the API is available. The full documentation for the transitional syntax is here: https://wiki.alliedmods.net/SourcePa...itional_Syntax Please let me know if you have any questions. |
Re: New API and Syntax
why, just why? at least before it was a language that was used by some other stuff like samp, but now this just makes it a new language to learn for a lot of ppl. javascript would be a better choice overall, as its the most widespread scripting language with the fastest JITs out there. also countless libraries have been written in js already...
|
Re: New API and Syntax
For developers looking to harness the methodmap syntax for an object-oriented API for interacting with game entities, check out these helpers includes.
Example of usage: PHP Code:
|
Re: New API and Syntax
If I may keep it short.
<--------------------------- |
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Totally not okay with that :
Code:
// Before: |
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Nevermind, thanks.
|
Re: New API and Syntax
Quote:
PHP Code:
PHP Code:
I myself look forward to a point in time when we have API calls like this: PHP Code:
|
Re: New API and Syntax
1. Can you separate a class's code from it's declaration? I see all the code in the methodmap declaration.
2. Is SM 1.7 stable enough to run on a live server? :3 |
Re: New API and Syntax
@BAILOPAN
If I have understand correctly, this is wrong : PHP Code:
PHP Code:
|
Re: New API and Syntax
Quote:
Quote:
Also, you should be able to run plugins compiled in 1.7 on a 1.6 server, again: at least for now. |
Re: New API and Syntax
So, basically this is replacing all the SourcePawn 2.0 stuff that was happening before?
|
Re: New API and Syntax
Quote:
2. Right now 1.7 is basically the same as 1.6 with some compiler changes. So it should be stable. I'm hoping that 1.7 will be mostly an API refactoring release. |
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Look like i have to start all over again and catch up with the rest of the new beginner.
|
Re: New API and Syntax
Quote:
See: https://travis-ci.org/50DKP/FF2-Official But other then that, taking a look at method maps documentation link, they are REALLY AWESOME! Much neater then current system as it actually makes things easier to understand. |
Re: New API and Syntax
Quote:
It looks to me more like a compiler bug (looking at the line numbers and error #) than "1.6 is incompatible with 1.7". |
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Again a milestone for every developer, nice!
|
Re: New API and Syntax
Hate me, but I loved SP for it's syntax. :(
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
I've adapted the smjansson includes and test plugin to the new syntax to see how it feels. Here
This was quite easy and i'm really pleased with the new syntax. Good job! Have one question though: How to deal with e.g. INVALID_HANDLE checks? Cast (i.e. tag) the methodmap as a Handle before comparison? |
Re: New API and Syntax
Looks awesome. Can't wait to give it a spin! :)
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
Using INVALID_HANDLE does work if I cast the methodmap to a Handle first, null on the other hand does only work if i cast it to the corresponding object type. E.g. this does not work unless the comparison is: f != StringMap:null Code:
#include <sourcemod> sm17.test.sp(6) : error 132: cannot coerce non-object type StringMap to object type null_t Is there a way to avoid tagging of null or the other value altogether? Also more questions if you don't mind:
And one bug report: it is possible to crash the compiler by using delete instead of CloseHandle. It is easily reproducible by changing line 1013 of the previously linked smjansson include to use delete and trying to compile the test plugin that comes with it. Sorry for not having a smaller and more specific testcase for this. Thanks! Edit: The wiki says: Quote:
|
Re: New API and Syntax
Quote:
Quote:
Quote:
Quote:
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Thank you! i've been waiting for something like this for a long time.
Please, don't stop even if it means breaking compatibility with old scripts. |
Re: New API and Syntax
Disliked this topic. For objects and classes we have C++
|
Re: New API and Syntax
But sometimes working with objects & classes is much easier...
|
Re: New API and Syntax
Nice, thanks for the fixes.
Found another bug regarding null passed as an any parameter though: Code:
Foo(any foo) {} A rather cosmetic issue: combining getters and setters works if used like this this.Processed = this.Processed + 1; which is nice. this.Processed++ garbles up the value though. This is at least the case for methodmaps deriving from StringMap and setting an integer in the trie, i.e. Code:
methodmap Foo < StringMap { |
Re: New API and Syntax
Sorry, fat-fingered and garbled your post up a bit. re: increment bug, will take a look soon.
null not flowing into any is intended. any makes the bit-encoding of values observable which is illegal for object types, and null is considered an object type. While not strictly necessary in this case, it makes sure we don't have any GC-safety problems with null in the future. |
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
Quote:
|
Re: New API and Syntax
So I read over this about 5 times. Maybe I'm stupid (I probably am) but I just don't see the need for this. The reason I got in coding 4 years ago, is because of the simplicity of the SourcePawn language and the need to make my server more unique. I remember not knowing what anything means (my worst enemy was tag mismatch), but still getting basic things done like printing to chat, setting health, etc. After awhile, I finally began to really learn why I was getting tag mismatch, why this was done, why that was done. With C#/Java or "C# Lite" as it's been called in the first post I still probably would have been unable to exactly understand why most things are done are that way. Sure I could probably make some basic edits (because words and I can read), but I wouldn't be able to get the true meaning of things as I did for SourcePawn. I think the current ease of language not only allows complete newbies to try, but it also opens doors. It certainly did for me.
Quote:
|
All times are GMT -4. The time now is 07:30. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.