mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
remove callresult from cli examples
This commit is contained in:
parent
9d53e1d748
commit
c5eeaab2c2
10 changed files with 60 additions and 112 deletions
|
@ -3,12 +3,12 @@
|
|||
use core::ffi::c_void;
|
||||
use core::mem::MaybeUninit;
|
||||
use libc::c_char;
|
||||
use roc_std::{RocCallResult, RocStr};
|
||||
use roc_std::RocStr;
|
||||
use std::ffi::CStr;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "roc__mainForHost_1_exposed"]
|
||||
fn roc_main(output: *mut RocCallResult<RocStr>) -> ();
|
||||
fn roc_main(output: *mut RocStr) -> ();
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@ -46,25 +46,18 @@ pub unsafe fn roc_panic(c_ptr: *mut c_void, tag_id: u32) {
|
|||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> isize {
|
||||
let mut call_result: MaybeUninit<RocCallResult<RocStr>> = MaybeUninit::uninit();
|
||||
let mut raw_output: MaybeUninit<RocStr> = MaybeUninit::uninit();
|
||||
|
||||
unsafe {
|
||||
roc_main(call_result.as_mut_ptr());
|
||||
roc_main(raw_output.as_mut_ptr());
|
||||
|
||||
let output = call_result.assume_init();
|
||||
let roc_str = raw_output.assume_init();
|
||||
|
||||
match output.into() {
|
||||
Ok(roc_str) => {
|
||||
let len = roc_str.len();
|
||||
let str_bytes = roc_str.get_bytes() as *const libc::c_void;
|
||||
let len = roc_str.len();
|
||||
let str_bytes = roc_str.get_bytes() as *const libc::c_void;
|
||||
|
||||
if libc::write(1, str_bytes, len) < 0 {
|
||||
panic!("Writing to stdout failed!");
|
||||
}
|
||||
}
|
||||
Err(msg) => {
|
||||
panic!("Roc failed with message: {}", msg);
|
||||
}
|
||||
if libc::write(1, str_bytes, len) < 0 {
|
||||
panic!("Writing to stdout failed!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue