1.98's sharper macro-use tracking flags the live-id macro globs five script modules kept without using; windows-strings' strlen extern takes *const c_char with a cast at the two call sites instead of tripping suspicious_runtime_symbol_definitions (PCSTR is transparent over *const u8, so the ABI never changed).
148 lines
4.1 KiB
Rust
148 lines
4.1 KiB
Rust
use crate::heap::*;
|
|
use crate::makepad_live_id::live_id::*;
|
|
use crate::native::*;
|
|
use crate::value::*;
|
|
use crate::*;
|
|
|
|
pub fn define_std_module(heap: &mut ScriptHeap, native: &mut ScriptNative) {
|
|
let std = heap.new_module(id!(std));
|
|
|
|
native.add_method(
|
|
heap,
|
|
std,
|
|
id_lut!(assert),
|
|
script_args!(v = NIL),
|
|
|vm, args| {
|
|
if let Some(x) = script_value!(vm, args.v).as_bool() {
|
|
if x == true {
|
|
return NIL;
|
|
}
|
|
}
|
|
script_err_assert_fail!(vm.bx.threads.cur_ref().trap, "assertion failed")
|
|
},
|
|
);
|
|
|
|
//native.add_method(heap, std, id!(err), script_args!(), |vm, _args|{
|
|
// return vm.thread.last_err
|
|
//});
|
|
|
|
let range = heap.new_with_proto(id!(range).into());
|
|
heap.set_value_def(std, id!(Range).into(), range.into());
|
|
|
|
native.add_method(
|
|
heap,
|
|
range,
|
|
id_lut!(step),
|
|
script_args!(x = 0.0),
|
|
|vm, args| {
|
|
if let Some(sself) = script_value!(vm, args.self).as_object() {
|
|
if let Some(x) = script_value!(vm, args.x).as_f64() {
|
|
set_script_value!(vm, sself.step = x);
|
|
}
|
|
return sself.into();
|
|
}
|
|
NIL
|
|
},
|
|
);
|
|
|
|
native.add_method(
|
|
heap,
|
|
std,
|
|
id_lut!(log),
|
|
script_args_def!(what = NIL),
|
|
|vm, args| {
|
|
let what = script_value!(vm, args.what);
|
|
vm.log(what);
|
|
NIL
|
|
},
|
|
);
|
|
|
|
native.add_method(
|
|
heap,
|
|
std,
|
|
id_lut!(print),
|
|
script_args_def!(what = NIL),
|
|
|vm, args| {
|
|
let what = script_value!(vm, args.what);
|
|
if vm
|
|
.string_with(what, |_vm, str| {
|
|
print!("{}", str);
|
|
})
|
|
.is_none()
|
|
{
|
|
let len = vm.bx.heap.cast_to_string_len(what);
|
|
let _ = vm.bx.heap.temp_string_with_preflight(
|
|
len,
|
|
"formatting print output",
|
|
|heap, temp| {
|
|
heap.cast_to_string(what, temp);
|
|
print!("{}", temp)
|
|
},
|
|
);
|
|
}
|
|
NIL
|
|
},
|
|
);
|
|
|
|
native.add_method(
|
|
heap,
|
|
std,
|
|
id_lut!(println),
|
|
script_args_def!(what = NIL),
|
|
|vm, args| {
|
|
let what = script_value!(vm, args.what);
|
|
if vm
|
|
.string_with(what, |_vm, str| {
|
|
println!("{}", str);
|
|
})
|
|
.is_none()
|
|
{
|
|
let len = vm.bx.heap.cast_to_string_len(what);
|
|
let is_empty = vm
|
|
.bx
|
|
.heap
|
|
.temp_string_with_preflight(
|
|
len,
|
|
"formatting println output",
|
|
|heap, temp| {
|
|
heap.cast_to_string(what, temp);
|
|
if temp.is_empty() {
|
|
return true;
|
|
}
|
|
println!("{}", temp);
|
|
false
|
|
},
|
|
)
|
|
.unwrap_or(false);
|
|
if is_empty {
|
|
return script_err_unexpected!(
|
|
vm.bx.threads.cur_ref().trap,
|
|
"println called with empty converted string, value: {:?}",
|
|
what
|
|
);
|
|
}
|
|
}
|
|
NIL
|
|
},
|
|
);
|
|
|
|
//native.add_method(heap, std, id!(to_metal_shader), script_args!(entry=NIL), |vm, _args|{
|
|
|
|
// return vm.thread.last_err
|
|
//});
|
|
|
|
native.add_method(
|
|
heap,
|
|
std,
|
|
id_lut!(set_type_default),
|
|
script_args!(obj = NIL),
|
|
|vm, args| {
|
|
if let Some(obj) = script_value!(vm, args.obj).as_object() {
|
|
if vm.bx.heap.set_type_default(obj) {
|
|
return obj.into();
|
|
}
|
|
}
|
|
NIL
|
|
},
|
|
);
|
|
}
|