...
This commit is contained in:
@@ -3017,5 +3017,33 @@ END;
|
||||
print("SM2: {} {}\n", p.a, p.b);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// OPTIONAL IF-ELSE COERCION
|
||||
// ============================================================
|
||||
{
|
||||
print("--- optional if-else coercion ---\n");
|
||||
OptF :: struct { width: ?f32; }
|
||||
x :f32: 10.0;
|
||||
|
||||
// null in then branch
|
||||
f1 := OptF.{ width = if true then null else x };
|
||||
print("opt-if1: {}\n", f1.width ?? 99.0);
|
||||
|
||||
// value in then branch, null in else
|
||||
f2 := OptF.{ width = if true then x else null };
|
||||
print("opt-if2: {}\n", f2.width ?? 99.0);
|
||||
|
||||
// both branches are values
|
||||
f3 := OptF.{ width = if false then 5.0 else x };
|
||||
print("opt-if3: {}\n", f3.width ?? 99.0);
|
||||
|
||||
// standalone optional variable
|
||||
val: ?f32 = if true then null else 42.0;
|
||||
print("opt-if4: {}\n", val ?? 0.0);
|
||||
|
||||
val2: ?f32 = if false then null else 42.0;
|
||||
print("opt-if5: {}\n", val2 ?? 0.0);
|
||||
}
|
||||
|
||||
print("=== DONE ===\n");
|
||||
}
|
||||
|
||||
7
examples/modules/stb_truetype.sx
Normal file
7
examples/modules/stb_truetype.sx
Normal file
@@ -0,0 +1,7 @@
|
||||
#import c {
|
||||
#include "vendors/stb_truetype/stb_truetype.h";
|
||||
#source "vendors/stb_truetype/stb_truetype_impl.c";
|
||||
|
||||
#include "vendors/file_utils/file_utils.h";
|
||||
#source "vendors/file_utils/file_utils.c";
|
||||
};
|
||||
Reference in New Issue
Block a user