X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=NewQC.textile;h=915a2750cd673cefbf2bc6b36eb5d7f583347b5e;hb=5a14052644b212ae69075381507d5b2f8159f98f;hp=880ebcdc266c352f3ff01c2be7ccc9c21c95cedf;hpb=9b79106f6159d48c46c03f4fafe56afd5b1e9fe8;p=xonotic%2Fxonotic.wiki.git diff --git a/NewQC.textile b/NewQC.textile index 880ebcd..915a275 100644 --- a/NewQC.textile +++ b/NewQC.textile @@ -1,48 +1,27 @@ h1. New QC Syntax +{{>toc}} + It is possible that at some point we decide to switch QC-compiler which requires some changes to the code. +*For more information see* http://dev.xonotic.org/projects/bocc + h2. Clean syntax: In fteqcc there are some ambiguities regarding fieldpointers, function pointers, and field-return-types etc. -A clean syntax is needed, *SUGGESTIONS ARE WELCOME*, my(blub's) current suggestion is: - -|_.definition|_.meaning| -|float foo(void)| function| -|float foo*(void)| function pointer| -|.float foo(void)| member: method/function pointer| -|..float foo(void)|/2. member: method/function pointer returning .float| -|..*float foo(void)| -|.*float foo*(void)| function pointer returning .float| -|.*float| fieldpointer| -|.*float foo(void)| fieldpointer: method/function pointer| -|.*.float foo(void)| fieldpointer: method/function pointer returning .float| - +A clean syntax is needed, the current implementation uses the following: |_.definition|_.meaning| +|float foo| global variable| +|float .foo| entity field| +|.float foo| fieldpointer| +|.float .foo| entity field of type fieldpointer| |float foo(void)| function| |float foo*(void)| function pointer| -|.float foo(void)| member: method/function pointer| -|..float foo(void)| member: method/function pointer returning .float| -|..*float .foo(void)| Member function returning pointer to float field -|.*float foo*(void)| function pointer returning .float| -|.*float| fieldpointer| -|.*float foo(void)| fieldpointer: method/function pointer| -|.*.float foo(void)| fieldpointer: method/function pointer returning .float| - -Additionally, at places where the definition of members or global functions is not allowed, they will be treated like fieldpointers. -So inside parameterlists or a functionbody the list is as follows: - -|_.definition|_.meaning| -|float foo(void)| *function pointer*| -|float foo*(void)| function pointer| -|.float foo(void)| *fieldpointer: method/function pointer*| -|..float foo(void)|/2. *fieldpointer: method/function pointer returning .float*| -|..*float foo(void)| -|.*float foo*(void)| function pointer returning .float| -|.*float| fieldpointer| -|.*float foo(void)| fieldpointer: method/function pointer| -|.*.float foo(void)| fieldpointer: method/function pointer returning .float| +|.float foo(void)| function returning a fieldpointer .float| +|.float foo*(void)| function pointer, returning a fieldpointer .float| +|float .foo(void)| entity field of type function returning float| +|.float .foo(void)| entity field of type function returning fieldpointer| h2. Function definitions: @@ -59,3 +38,48 @@ From now on, the code does what the first instinct tells you: it creates a global with the initial value 3. Contrary to old QC, where it created a constant. To create a constant use:
const float x = 3
+ +h2. Extendable functions: + +Since menuQC has some funny macro: ACCUMULATE_FUNCTIONS, it seemed like a nice syntactical sugar to allow the following: + +
float myfunc() extendable
+{
+    float mylocal = 3;
+}
+
+/* other code */
+
+float myfunc()
+{
+    mylocal += 5;
+    if (mylocal > 20)
+        return mylocal;
+}
+
+/* optionally: */
+float myfunc() final
+{
+    return 3;
+}
+
+ +h2. Variadic parameters (do not use yet) + +(This might get changed to be more flexible so do not rely on this syntax...) + +Another "enhancement" is the possibility to have functions with variadic parameter lists. However, the only way to sanely access them (until pointers are allowed) is via a recursive way. +Here's an example that assumes float parameters and prints them one after the other: +
void printfloats(float count, float first, ...)
+{
+    if (count <= 0) // if there are no parameters, return
+        return;
+    if (count == 1) { // If there's one parameter, print it, plus a new-line
+        print(strcat(ftos(first), "\n"));
+        return;
+    }
+    // Otherwise we have multiple parameters left, so print the float, and add a comma
+    print(strcat(ftos(first), ", "));
+    myprint(count-1, ...);
+}
+So myprint(4, 1, 2, 3, 4) would print "1, 2, 3, 4\n"