Skip to content

Commit

Permalink
Redscript
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Oct 1, 2024
1 parent 195f644 commit 15581b3
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
1 change: 1 addition & 0 deletions LANGUAGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Rakefile (rake,rakefile)
Raku (raku,rakumod,rakutest,rakudoc,t)
Razor (cshtml,razor)
ReasonML (re,rei)
Redscript (reds)
Report Definition Language (rdl)
ReScript (res,resi)
ReStructuredText (rst)
Expand Down
6 changes: 3 additions & 3 deletions SCC-OUTPUT-REPORT.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<th>447</th>
<th>7659</th>
<th>1529</th>
<th>254544</th>
<th>254636</th>
<th>4067</th>
</tr><tr>
<td>processor/formatters.go</td>
Expand Down Expand Up @@ -288,7 +288,7 @@
<td>0</td>
<td>4</td>
<td>0</td>
<td>22205</td>
<td>22297</td>
<td>5</td>
</tr></tbody>
<tfoot><tr>
Expand All @@ -299,7 +299,7 @@
<th>447</th>
<th>7659</th>
<th>1529</th>
<th>254544</th>
<th>254636</th>
<th>4067</th>
</tr>
<tr>
Expand Down
84 changes: 84 additions & 0 deletions examples/language/redscript.reds
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// 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");
}

// you can trigger calls when game functions are called
@wrapMethod(CraftingSystem)
private final func ProcessCraftSkill(xpAmount: Int32, craftedItem: StatsObjectID) {
// this calls the original function. Don't omit this - use replaceMethod instead!
wrappedMethod(xpAmount, craftedItem);
// you can now do your own stuff.
// Or even do your own stuff _first_, modify the parameters passed to the
// original call.
}
21 changes: 21 additions & 0 deletions languages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5248,6 +5248,27 @@
}
]
},
"Redscript": {
"complexitychecks": [
"for ",
"@if(",
"switch ",
"while ",
"else ",
"func ",
"-> "
],
"extensions": ["reds"],
"line_comment": ["//", "///"],
"multi_line": [["/*", "*/"]],
"nestedmultiline": true,
"quotes": [
{
"end": "\"",
"start": "\""
}
]
},
"Report Definition Language": {
"complexitychecks": [],
"extensions": ["rdl"],
Expand Down
2 changes: 1 addition & 1 deletion processor/constants.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ specificLanguages=(
'R '
'Racket '
'Rakefile '
'Redscript '
'Shell '
'Sieve '
'Slang '
Expand Down

0 comments on commit 15581b3

Please sign in to comment.