Skip to content

Commit

Permalink
Implement sign() (#2207)
Browse files Browse the repository at this point in the history
Co-authored-by: ike709 <[email protected]>
  • Loading branch information
ike709 and ike709 authored Feb 12, 2025
1 parent c237a04 commit 1b19fed
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/compiler-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ jobs:
ref: dev
path: nebula
- name: Compile Nebula Dev
run: main\bin\DMCompiler\DMCompiler.exe nebula\nebula.dme --suppress-unimplemented
run: main\bin\DMCompiler\DMCompiler.exe nebula\nebula.dme --suppress-unimplemented --version=516.1655
- name: Checkout /vg/station Master
uses: actions/checkout@v2
with:
repository: vgstation-coders/vgstation13
ref: Bleeding-Edge
path: vg
- name: Compile /vg/station Master
run: main\bin\DMCompiler\DMCompiler.exe vg\vgstation13.dme --suppress-unimplemented
run: main\bin\DMCompiler\DMCompiler.exe vg\vgstation13.dme --suppress-unimplemented --version=516.1655
- name: Checkout CM Master
uses: actions/checkout@v2
with:
Expand All @@ -99,4 +99,4 @@ jobs:
ref: master
path: aurora
- name: Compile Aurora Master
run: main\bin\DMCompiler\DMCompiler.exe aurora\aurorastation.dme --suppress-unimplemented
run: main\bin\DMCompiler\DMCompiler.exe aurora\aurorastation.dme --suppress-unimplemented --version=516.1655
10 changes: 10 additions & 0 deletions Content.Tests/DMProject/Tests/Builtins/sign.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

/proc/RunTest()
ASSERT(sign(5.2) == 1)
ASSERT(sign(-5.2) == -1)
ASSERT(sign(0) == 0)
ASSERT(sign(null) == 0)
ASSERT(sign("") == 0)
ASSERT(sign("foo") == 0)
ASSERT(sign(list(1)) == 0)

1 change: 1 addition & 0 deletions DMCompiler/DMStandard/_Standard.dm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ proc/roll(ndice = 1, sides) as num
proc/round(A, B) as num
proc/sha1(input) as text|null
proc/shutdown(Addr,Natural = 0)
proc/sign(A) as num
proc/sleep(Delay)
proc/sorttext(T1, T2) as num
proc/sorttextEx(T1, T2) as num
Expand Down
1 change: 1 addition & 0 deletions OpenDreamRuntime/Procs/Native/DreamProcNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static void SetupNativeProcs(DreamObjectTree objectTree) {
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_round);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_sha1);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_shutdown);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_sign);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_sleep);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_sorttext);
objectTree.SetGlobalNativeProc(DreamProcNativeRoot.NativeProc_sorttextEx);
Expand Down
16 changes: 16 additions & 0 deletions OpenDreamRuntime/Procs/Native/DreamProcNativeRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,22 @@ public static DreamValue NativeProc_shutdown(NativeProc.Bundle bundle, DreamObje
return DreamValue.Null;
}

[DreamProc("sign")]
[DreamProcParameter("A", Type = DreamValueTypeFlag.Float)]
public static DreamValue NativeProc_sign(NativeProc.Bundle bundle, DreamObject? src, DreamObject? usr) {
if (bundle.Arguments.Length != 1) throw new Exception($"expected 1 argument (found {bundle.Arguments.Length})");
DreamValue arg = bundle.GetArgument(0, "A");

// Any non-num returns 0
if (!arg.TryGetValueAsFloat(out var value)) return new DreamValue(0);

return value switch {
0 => new DreamValue(0),
< 0 => new DreamValue(-1),
_ => new DreamValue(1)
};
}

[DreamProc("sleep")]
[DreamProcParameter("Delay", Type = DreamValueTypeFlag.Float)]
public static async Task<DreamValue> NativeProc_sleep(AsyncNativeProc.State state) {
Expand Down

0 comments on commit 1b19fed

Please sign in to comment.