summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRom's <romain.kelifa@gmail.com>2023-05-03 12:22:59 +0700
committerGitHub <noreply@github.com>2023-05-03 07:22:59 +0200
commita99eb5f218f9f157232fea142da22e903335fd1d (patch)
tree745faf0ba445c1900b6902f646a968c61c9f4644
parentd6cb435152e9907af2bd62acd7134406353c6a85 (diff)
Add support for Redscript (#994)
-rw-r--r--languages.json8
-rw-r--r--tests/data/redscript.reds75
2 files changed, 83 insertions, 0 deletions
diff --git a/languages.json b/languages.json
index 94d85ec..86d4365 100644
--- a/languages.json
+++ b/languages.json
@@ -1204,6 +1204,14 @@
"multi_line_comments": [["<!--", "-->"], ["@*", "*@"]],
"extensions": ["cshtml"]
},
+ "Redscript": {
+ "name": "Redscript",
+ "line_comment": ["//", "///"],
+ "multi_line_comments": [["/*", "*/"]],
+ "quotes": [["\\\"", "\\\""]],
+ "nested": true,
+ "extensions": ["reds"]
+ },
"Renpy": {
"name": "Ren'Py",
"line_comment": ["#"],
diff --git a/tests/data/redscript.reds b/tests/data/redscript.reds
new file mode 100644
index 0000000..55edc79
--- /dev/null
+++ b/tests/data/redscript.reds
@@ -0,0 +1,75 @@
+// 75 lines 47 code 20 comments 8 blanks
+
+// redscript allows line comments
+/* as well as block comments */
+
+// it supports global functions
+func add2(x: Int32, y: Int32) -> Int32 {
+ return x + y;
+}
+
+// functions without a type annotation default to Void return type
+func tutorial() {
+ let x: Int32 = 10;
+ // compiler can infer types for local variables, y will be Int32
+ let y = 20;
+ // it supports arithmetic
+ let sum = x + y + 13;
+ // as well as mutation
+ let mutable = 0;
+ mutable += 10;
+ // numbers with decimal points default to type Float
+ let num = 10.0;
+ // you can cast between some types
+ let uint: Uint8 = Cast(10);
+ // array literals
+ let arr = [1, 2, 3];
+ // array iteration
+ for item in arr {
+ // logging and string operations
+ Log("at " + ToString(item));
+ }
+}
+
+// you can define your own classes
+public class IntTuple {
+ let fst: Int32;
+ let snd: Int32;
+
+ // you can define static member functions
+ public static func Create(fst: Int32, snd: Int32) -> ref<IntTuple> {
+ let tuple = new IntTuple();
+ tuple.fst = fst;
+ tuple.snd = snd;
+ return tuple;
+ }
+
+ public func Swap() {
+ let tmp = this.fst;
+ this.fst = this.snd;
+ this.snd = tmp;
+ }
+}
+
+// you can replace existing in-game methods by specifying the class they belong to
+@replaceMethod(CraftingSystem)
+private final func ProcessCraftSkill(xpAmount: Int32, craftedItem: StatsObjectID) {
+ // instantiate a class using the new operator
+ let xpEvent = new ExperiencePointsEvent();
+ xpEvent.amount = xpAmount * 100;
+ xpEvent.type = gamedataProficiencyType.Crafting;
+ GetPlayer(this.GetGameInstance()).QueueEvent(xpEvent);
+}
+
+// you can add new methods to existing classes as well
+// they are visible to other code using the class
+@addMethod(BackpackMainGameController)
+private final func DisassembleAllJunkItems() -> Void {
+ let items = this.m_InventoryManager.GetPlayerItemsByType(gamedataItemType.Gen_Junk);
+ let i = 0;
+ for item in items {
+ ItemActionsHelper.DisassembleItem(this.m_player, InventoryItemData.GetID(item));
+ };
+ // some methods require CName literals, they need to be prefixed with the n letter
+ this.PlaySound(n"Item", n"OnBuy");
+} \ No newline at end of file