Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

@mizchi
CreatedNovember 2, 2025 16:48
    • Star(0)You must be signed in to star a gist
    • Fork(0)You must be signed in to fork a gist

    Select an option

    Save mizchi/6551245d29d121bc90e462b3ed9b7101 to your computer and use it in GitHub Desktop.

    Moonbit FFI Core

    ///|#externalpubtypeJsValue///|pubfn[T]JsValue::cast(self :JsValue)->T="%identity"///|pubfn[A,B]unsafe_cast(a :A)->B="%identity"///|pubfn[A]js(a :A)->JsValue="%identity"extern"js"fnobject_is(a :JsValue,b :JsValue)->Bool=#| (v,k) => Object.is(v, k)pubimplEqforJsValuewithequal(self,other)->Bool {object_is(self,other)}pubimplShowforJsValuewithoutput(self,logger) {logger.write_string(self.to_string())}pubimplShowforJsValuewithto_string(self) {ifself==undefined() {"undefined"  }else {self.call_method("toString", []).cast()  }}pubextern"js"fnJsValue::get(self :Self,key:String)->JsValue=#| (v,k) => v[k]pubextern"js"fnJsValue::set(self :Self,key:String,value:JsValue)->Unit=#| (o,k,v) => o[k] = vpubextern"js"fnJsValue::call(self :Self,args:Array[JsValue])->JsValue=#| (v, a) => v(...a)pubextern"js"fnJsValue::call_method(self :Self,key:String,args:Array[JsValue])->JsValue=#| (v, key, a) => v[key](...a)pubextern"js"fnundefined()->JsValue=#| () => undefinedpubextern"js"fnnew_object()->JsValue=#| () => ({})test {letv1 :JsValue=js(42)letv2 :JsValue=js(42)assert_eq(v1,v2)letv:Int=v1.cast()assert_eq(v,42)letobj=new_object()obj.set("key",js("value"))obj.call_method("hasOwnProperty", [js("key")]).cast()|>assert_trueletval:String=obj.get("key").cast()assert_eq(val,"value")}fnmain {}
    Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

    [8]ページ先頭

    ©2009-2025 Movatter.jp