{"id":12300,"date":"2025-07-06T17:57:10","date_gmt":"2025-07-06T08:57:10","guid":{"rendered":"https:\/\/www.webcyou.com\/?p=12300"},"modified":"2025-07-06T17:58:11","modified_gmt":"2025-07-06T08:58:11","slug":"godot-4-webassembly%e3%81%a7%e6%a7%98%e3%80%85%e3%81%aa%e3%83%87%e3%83%bc%e3%82%bf%e3%83%95%e3%82%a9%e3%83%bc%e3%83%9e%e3%83%83%e3%83%88%e3%82%92%e5%87%a6%e7%90%86","status":"publish","type":"post","link":"https:\/\/www.webcyou.com\/?p=12300","title":{"rendered":"Godot 4 &#038; WebAssembly\u3067\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u51e6\u7406"},"content":{"rendered":"\n<p>\u3069\u3082\u3067\u3059\u3002<\/p>\n<p>\u524d\u56de\u300c<a href=\"https:\/\/www.webcyou.com\/?p=12274\">Godot 4 &amp; WebAssembly\u3067\u3001Hello WebAssembly! \u2013 godot-wasm<\/a>\u300d\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u8e0f\u307f\u8fbc\u3093\u3060\u5185\u5bb9\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>godot-wasm\u3092\u7528\u3044\u305f\u30b5\u30f3\u30d7\u30eb\u306f\u3001\u3053\u3061\u3089\u306e<a href=\"https:\/\/github.com\/ashtonmeuser\/godot-wasm\/wiki\/Examples\">\u30da\u30fc\u30b8<\/a>\u306b\u8272\u3005\u306a\u30c7\u30e2\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u53c2\u8003\u306b\u3059\u308b\u3068\u826f\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>WebAssembly\u5316\u3055\u308c\u305fDoom\u3082\u3001\u30cc\u30eb\u30cc\u30eb\u52d5\u3044\u3066\u697d\u3057\u3044\u3067\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-12301\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/doom-1024x691.png\" alt=\"\" width=\"501\" height=\"338\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/doom-1024x691.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/doom-300x202.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/doom-768x518.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/doom.png 1376w\" sizes=\"auto, (max-width: 501px) 100vw, 501px\" \/><\/p>\n<p>Godot\u5074\u306eGDScript\u306f\u3001\u308f\u305a\u304b34\u884c\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">extends Control\n\n@onready var wasm = Wasm.new()\n@onready var memory = WasmMemory.new()\nvar image = Image.new()\nvar keys = { KEY_ENTER: 13, KEY_BACKSPACE: 127, KEY_SPACE: 32, KEY_LEFT: 0xac, KEY_RIGHT: 0xae, KEY_UP: 0xad, KEY_DOWN: 0xaf, KEY_CTRL: 0x80+0x1d, KEY_ALT: 0x80+0x38, KEY_ESCAPE: 27, KEY_TAB: 9, KEY_SHIFT: 16 }\n\nfunc _ready():\n    for k in range(KEY_A, KEY_Z + 1).map(func(x): return { x: x + 32 }) + range(KEY_0, KEY_9 + 1).map(func(x): return { x: x }) + range(KEY_F1, KEY_F12 + 1).map(func(x): return { x: 187 + x - KEY_F1 }): keys.merge(k)\n    image = Image.create(640, 400, false, Image.FORMAT_RGBA8)\n    $TextureRect.texture.set_image(image)\n    memory.grow(108)\n    var imports = {\n        \"functions\": { \"js.js_console_log\": [self, \"stdout\"], \"js.js_draw_screen\": [self, \"draw_screen\"], \"js.js_milliseconds_since_start\": [Time, \"get_ticks_msec\"], \"js.js_stdout\": [self, \"stdout\"], \"js.js_stderr\": [self, \"stderr\"] },\n        \"memory\": memory,\n    }\n    wasm.load(FileAccess.get_file_as_bytes(\"res:\/\/doom.wasm\"), imports)\n    wasm.function(\"main\", [0, 0])\n\nfunc _process(_delta):\n    wasm.function(\"doom_loop_step\")\n\nfunc _input(event):\n    if event is InputEventKey and !event.is_echo(): wasm.function(\"add_browser_event\", [int(!event.is_pressed()), keys.get(event.keycode, 0)])\n\nfunc draw_screen(offset):\n    image.set_data(640, 400, false, Image.FORMAT_RGBA8, memory.seek(offset).get_data(640 * 400 * 4)[1])\n    $TextureRect.texture.update(image)\n\nfunc stdout(offset, length):\n    print(memory.seek(offset).get_utf8_string(length))\n\nfunc stderr(offset, length):\n    push_warning(memory.seek(offset).get_utf8_string(length))<\/pre>\n<p><a href=\"https:\/\/github.com\/ashtonmeuser\/godot-wasm-doom\/blob\/master\/Main.gd\" target=\"_blank\" rel=\"noopener\">\u5b9f\u30bd\u30fc\u30b9<\/a><\/p>\n<p>WebAssembly\u306e\u6d41\u7528\u6027\u304c\u308f\u304b\u308a\u307e\u3059\u306d\u3002<\/p>\n<p>WebAssembly\u306e\u4ed5\u69d8\u306b\u95a2\u3057\u3066\u306f\u3044\u305a\u308c\u307e\u3068\u3081\u305f\u3044\u306a\u3068\u601d\u3044\u3064\u3064\u3001\u4eca\u56de\u306f\u300c<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\">wasm32-unknown-unknown<\/span><!-- notionvc: b15d4be4-3333-44fc-9f41-eed5c53f3685 -->\u300d\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3067\u51fa\u529b\u3055\u308c\u305fWebAssembly\u3092Godot\u306bimport\u3057\u3066\u3001\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u30c7\u30fc\u30bf\u306e\u3084\u308a\u53d6\u308a\u3057\u3088\u3046\u3002\u3068\u3044\u3063\u305f\u3068\u3053\u308d\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4ee5\u524d\u306f\u3001Web\u7528\u3068\u3057\u3066\u51fa\u529b\u3059\u308b\u305f\u3081\u306b\u3001<span class=\"notion-enable-hover\" spellcheck=\"false\" data-token-index=\"0\">wasm-bindgen\u3092\u7528\u3044\u3066\u3044\u305f\u306e\u3067\u3059\u304c\u3001wasm32-unknown-unknown\u3060\u3068\u307e\u3042\u307e\u3042\u624b\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u306d\u3002\u305b\u3081\u3066\u3001WebAssembly Component Model \u3067\u6271\u3048\u308c\u3070\u826f\u3044\u306a\u3068\u601d\u3044\u307e\u3057\u305f\u3002<\/span><\/p>\n<p><!-- notionvc: bbc8bad3-b5f6-41ac-9625-bda099c0db91 --><\/p>\n<h4>\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092WASM\u306b\u9001\u4fe1\u30fb\u53d6\u5f97<\/h4>\n<p>\u3067\u306f\u65e9\u901f\u3002<\/p>\n<p>\u5148\u306b\u30bd\u30fc\u30b9\u306a\u3069\u3092\u53c2\u7167\u3057\u305f\u3044\u65b9\u306f<a href=\"https:\/\/github.com\/godot-game-samples\/godot-wasm-multi\" target=\"_blank\" rel=\"noopener\">\u3053\u3061\u3089<\/a>\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone  wp-image-12302\" src=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/screen-1024x674.png\" alt=\"\" width=\"503\" height=\"331\" srcset=\"https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/screen-1024x674.png 1024w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/screen-300x198.png 300w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/screen-768x506.png 768w, https:\/\/www.webcyou.com\/wp-content\/uploads\/2025\/07\/screen.png 1300w\" sizes=\"auto, (max-width: 503px) 100vw, 503px\" \/><\/p>\n<p>\u524d\u56de\u540c\u69d8\u300c<a href=\"https:\/\/github.com\/ashtonmeuser\/godot-wasm\">godot-wasm<\/a>\u300d\u3092\u5229\u7528\u3057\u307e\u3059\u3002<\/p>\n<p>\u5de6\u5074\u306eInput\u306b\u3066\u3001String\u3001Int\u3001ByteArray\u3001JSON\u306e\u4efb\u610f\u306e\u5024\u3092\u5165\u529b\u3057\u300cSubmit\u300d\u3092\u62bc\u4e0b\u3059\u308b\u3068\u7d50\u679c\u304c\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u51fa\u529b\u306b\u95a2\u3057\u3066\u3001<\/p>\n<ul>\n<li>DebugLog\u306f\u3001\u5165\u529b\u5024\u3092\u305d\u306e\u307e\u307e\u52a0\u5de5\u306a\u3057\u3067\u8868\u793a\u3057\u307e\u3059\u3002<\/li>\n<li>WasmLog\u306f\u3001\u5165\u529b\u3092Wasm\u306b\u6e21\u3057\u3001\u5909\u63db\u306a\u3057\u3067\u53d6\u5f97\u3057\u8868\u793a\u3057\u307e\u3059\u3002<\/li>\n<li>WasmCalcLog\u306f\u3001\u5165\u529b\u3092Wasm\u306b\u6e21\u3057\u3001Wasm\u306b\u3088\u308b\u51e6\u7406\u5f8c\u306b\u53d6\u5f97\u3057\u8868\u793a\u3057\u307e\u3059\u3002\uff08String\uff1a\u53cd\u8ee2\u3001Int\uff1a2\u500d\u3001ByteArray\uff1a\u53cd\u8ee2\u3001JSON\uff1aname\u306f\u53cd\u8ee2\u3001level\u306f2\u500d\uff09<\/li>\n<\/ul>\n<p>Godot \u3068 WebAssembly (Rust) \u306e\u9593\u3067 String\u3001int\u3001PackedByteArray\u3001JSON \u306e\u5024\u3092\u4fdd\u5b58\u3001\u53d6\u5f97\u3059\u308b\u6d41\u308c\u3067\u3059\u304c\u3001\u3059\u3079\u3066\u306e\u30c7\u30fc\u30bf\u306f store_* \u95a2\u6570\u306b\u3088\u3063\u3066\u30ea\u30cb\u30a2\u30e1\u30e2\u30ea\u306b\u683c\u7d0d\u3055\u308c\u3001WebAssembly \u304b\u3089\u8fd4\u3055\u308c\u308b\u30e1\u30e2\u30ea\u30dd\u30a4\u30f3\u30bf\u3092\u4f7f\u7528\u3057\u3066\u53d6\u5f97\u3059\u308b\u5f62\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<div class=\"markdown-heading\" dir=\"auto\">\n<p class=\"heading-element\" dir=\"auto\" tabindex=\"-1\"><strong>Godot-side: Store Functions<\/strong><\/p>\n<a id=\"user-content-godot-side-store-functions\" class=\"anchor\" href=\"https:\/\/github.com\/godot-game-samples\/godot-wasm-multi#godot-side-store-functions\" aria-label=\"Permalink: Godot-side: Store Functions\"><\/a><\/div>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">func store_string(text: String, offset := 0) -&gt; int:\n    var bytes: PackedByteArray = text.to_utf8_buffer()\n    wasm.memory.seek(offset).put_data(bytes)\n    wasm.function(\"store_data\", [offset, bytes.size()])\n    return bytes.size()\n\nfunc store_int(value: int, offset: int) -&gt; void:\n    var bytes := PackedByteArray()\n    bytes.append(value &amp; 0xFF)\n    bytes.append((value &gt;&gt; 8) &amp; 0xFF)\n    bytes.append((value &gt;&gt; 16) &amp; 0xFF)\n    bytes.append((value &gt;&gt; 24) &amp; 0xFF)\n    wasm.memory.seek(offset).put_data(bytes)\n\nfunc store_bytes(bytes: PackedByteArray, offset := 0) -&gt; int:\n    wasm.memory.seek(offset).put_data(bytes)\n    wasm.function(\"store_data\", [offset, bytes.size()])\n    return bytes.size()<\/pre>\n<\/div>\n<p>\u5404\u30c7\u30fc\u30bf\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u306e\u5f62\u5f0f\u306b\u3088\u3063\u3066\u524d\u51e6\u7406\u304c\u5fc5\u8981\u3068\u306a\u308a\u307e\u3059\u304c\u3001\u57fa\u672c\u30d0\u30a4\u30c8\u5217\u3068\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<p>JSON\u30c7\u30fc\u30bf\u3082\u3001store_string()\u3092\u4f7f\u7528\u3057\u3066UTF-8\u30a8\u30f3\u30b3\u30fc\u30c9\u3055\u308c\u305f\u6587\u5b57\u5217\u3068\u3057\u3066\u683c\u7d0d\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3057\u305f\u5f8c\u3001get_data_ptr\u3092\u4f7f\u3063\u3066Wasm\u304b\u3089\u305d\u306e\u30dd\u30a4\u30f3\u30bf\u3092\u53d6\u5f97\u3057\u3001\u30e1\u30e2\u30ea\u304b\u3089\u8aad\u307f\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p class=\"heading-element\" dir=\"auto\" tabindex=\"-1\"><strong>Godot-side<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">func get_string(text: String) -&gt; String:\n    var offset := 0\n    var length = store_string(text, offset)\n    var ptr = wasm.function(\"get_data_ptr\")\n    var result = wasm.memory.seek(ptr).get_data(length)\n    return get_result_string(result)<\/pre>\n<div class=\"markdown-heading\" dir=\"auto\">\n<p class=\"heading-element\" dir=\"auto\" tabindex=\"-1\"><strong>Rust-side: Wasm Data Handling<\/strong><\/p>\n<a id=\"user-content-rust-side-wasm-data-handling\" class=\"anchor\" href=\"https:\/\/github.com\/godot-game-samples\/godot-wasm-multi#rust-side-wasm-data-handling\" aria-label=\"Permalink: Rust-side: Wasm Data Handling\"><\/a><\/div>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn store_data(ptr: *const u8, len: usize) {\n    let data = unsafe { std::slice::from_raw_parts(ptr, len) };\n    let mut guard = BUFFER.lock();\n    *guard = Some(data.to_vec());\n}\n\n#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn get_data_ptr() -&gt; *const u8 {\n    let guard = BUFFER.lock();\n    guard.as_ref().map(|buf| buf.as_ptr()).unwrap_or(core::ptr::null())\n}<\/pre>\n<p>Rust\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u53b3\u683c\u5316\u306e\u9055\u3044\u304c\u3042\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>2021edition\u3067\u306f\u3001 #[no_mangle] \u3067\u826f\u304b\u3063\u305f\u306e\u304c\u30012024edition\u3067\u306f\u3001#[unsafe(no_mangle)]\u3068unsafe\u304c\u6c42\u3081\u3089\u308c\u308b\u3057\u3001pub unsafe extern &#8220;C&#8221; fn\u3068\u95a2\u6570\u306bunsafe\u8a18\u8ff0\u304c\u3042\u308c\u3070\u3001\u95a2\u6570\u5185\u306b\u306funsafe\u8a18\u8ff0\u8a18\u8ff0\u304c\u5fc5\u8981\u306a\u304b\u3063\u305f\u306e\u306b\u30012024edition\u3067\u306f\u3001\u5185\u90e8\u306e unsafe \u306a\u64cd\u4f5c\u306f\u660e\u793a\u7684\u306a <code data-start=\"325\" data-end=\"341\">unsafe { ... }<\/code> \u30d6\u30ed\u30c3\u30af\u306b\u5165\u308c\u306a\u3044\u3068\u3044\u3051\u306a\u304f\u306a\u308a\u3001unsafe { std::slice::from_raw_parts(ptr, len) };\u3068\u5fc5\u8981\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001store\u51e6\u7406\u3082\u3001\u4ee5\u4e0b\u306e\u69d8\u306b\u3067\u304d\u3066\u3044\u305f\u306e\u304c\u3001<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">#[no_mangle]\npub unsafe extern \"C\" fn store_data(ptr: *const u8, len: usize) {\n    let data = std::slice::from_raw_parts(ptr, len);\n    BUFFER = Some(data.to_vec());\n}<\/pre>\n<\/div>\n<p>lazy_static\u3092\u7528\u3044\u3066\u3001BUFFER\u306e\u5b9a\u7fa9\u3068\u521d\u671f\u5316\u304c\u5fc5\u8981\u3068\u306a\u308a\u3001BUFFER \u3078\u306e\u30a2\u30af\u30bb\u30b9\u306f\u5fc5\u305a .lock() \u3092\u4f7f\u3063\u3066\u6392\u4ed6\u5236\u5fa1\u3057\u306a\u3051\u308c\u3070\u3044\u3051\u306a\u304f\u306a\u308a\u307e\u3057\u305f\u3002<!-- --> <!-- notionvc: 55e9bba9-9c61-42c7-8a88-f25cd1b2f378 --><\/p>\n<div class=\"snippet-clipboard-content notranslate position-relative overflow-auto\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">lazy_static! {\n    static ref BUFFER: Mutex&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt; = Mutex::new(None);\n    static ref RESULT_BUFFER: Mutex&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt; = Mutex::new(None);\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b <code data-start=\"217\" data-end=\"231\">lazy_static!<\/code> \u30de\u30af\u30ed\u3092\u7528\u3044\u308b\u3053\u3068\u3067\u3001\u30b0\u30ed\u30fc\u30d0\u30eb\u306a <code data-start=\"250\" data-end=\"274\">Mutex&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt;<\/code> \u3092\u5b89\u5168\u306b\u521d\u671f\u5316\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn store_data(ptr: *const u8, len: usize) {\n    let data = unsafe { std::slice::from_raw_parts(ptr, len) };\n    let mut guard = BUFFER.lock();\n    *guard = Some(data.to_vec());\n}<\/pre>\n<p><code data-start=\"358\" data-end=\"366\">BUFFER<\/code> \u306f <code data-start=\"369\" data-end=\"376\">Mutex<\/code> \u3067\u30e9\u30c3\u30d7\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001\u30a2\u30af\u30bb\u30b9\u3059\u308b\u306b\u306f <code data-start=\"398\" data-end=\"407\">.lock()<\/code> \u3092\u4f7f\u3063\u3066\u30ed\u30c3\u30af\u3092\u53d6\u5f97\u3057\u3001\u6392\u4ed6\u5236\u5fa1\u3092\u884c\u3046\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u30b9\u30ec\u30c3\u30c9\u9593\u3067\u30c7\u30fc\u30bf\u7af6\u5408\u3092\u9632\u3050\u305f\u3081\u306b\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<\/div>\n<p>\u3068\u3001\u672c\u984c\u3068\u9038\u308c\u305fRust\u306e\u4ed5\u69d8\u306b\u306a\u308a\u307e\u3057\u305f\u304c\u3001\u3061\u3087\u3063\u3068\u30cf\u30de\u3063\u305f\u70b9\u3067\u3057\u305f\u3002<\/p>\n<p>\u5143\u306b\u623b\u308b\u3068\u3001<\/p>\n<div class=\"markdown-heading\" dir=\"auto\">\n<p class=\"heading-element\" dir=\"auto\" tabindex=\"-1\"><strong>Rust-side: Processing with Result Buffer<\/strong><\/p>\n<a id=\"user-content-rust-side-processing-with-result-buffer\" class=\"anchor\" href=\"https:\/\/github.com\/godot-game-samples\/godot-wasm-multi\/tree\/main#rust-side-processing-with-result-buffer\" aria-label=\"Permalink: Rust-side: Processing with Result Buffer\"><\/a><\/div>\n<p>\u5165\u529b\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u5909\u63db\u3092\u884c\u3046\u969b\u306f\u3001\uff08\u4f8b\u3048\u3070\u6587\u5b57\u5217\u3092\u53cd\u8ee2\u3055\u305b\u308b\uff09\u3001\u5225\u306e\u30d0\u30c3\u30d5\u30a1\u3068\u3057\u3066\u300cRESULT_BUFFER\u300d\u3092\u4f7f\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">lazy_static! {\n    static ref BUFFER: Mutex&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt; = Mutex::new(None);\n    static ref RESULT_BUFFER: Mutex&lt;Option&lt;Vec&lt;u8&gt;&gt;&gt; = Mutex::new(None);\n}\n\n#[unsafe(no_mangle)]\npub extern \"C\" fn reverse_string() {\n    let buffer_guard = BUFFER.lock();\n    let mut result_guard = RESULT_BUFFER.lock();\n\n    if let Some(ref data) = *buffer_guard {\n        if let Ok(input_str) = std::str::from_utf8(data) {\n            let reversed: String = input_str.chars().rev().collect();\n            *result_guard = Some(reversed.into_bytes());\n        } else {\n            *result_guard = Some(\"invalid_utf8\".as_bytes().to_vec());\n        }\n    } else {\n        *result_guard = Some(\"no_data\".as_bytes().to_vec());\n    }\n}<\/pre>\n<p>\u3053\u306e\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3001\u4ee5\u4e0b\u306e\u95a2\u6570\u3067\u30dd\u30a4\u30f3\u30bf\u3092\u53d6\u5f97<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"rust\">#[unsafe(no_mangle)]\npub unsafe extern \"C\" fn get_result_buffer_ptr() -&gt; *const u8 {\n    let guard = RESULT_BUFFER.lock();\n    guard.as_ref().map(|buf| buf.as_ptr()).unwrap_or(core::ptr::null())\n}<\/pre>\n<div class=\"markdown-heading\" dir=\"auto\">\n<p class=\"heading-element\" dir=\"auto\" tabindex=\"-1\"><strong>Godot-side: Read Transformed Result<\/strong><\/p>\n<a id=\"user-content-godot-side-read-transformed-result\" class=\"anchor\" href=\"https:\/\/github.com\/godot-game-samples\/godot-wasm-multi\/tree\/main#godot-side-read-transformed-result\" aria-label=\"Permalink: Godot-side: Read Transformed Result\"><\/a><\/div>\n<p>Godot\u5074\u3067\u306f\u3001\u51e6\u7406\u5f8c\u306b\u5909\u63db\u3055\u308c\u305f\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u51fa\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\">func get_string_reverse(text: String) -&gt; String:\n    var offset := 0\n    var length = store_string(text, offset)\n    wasm.function(\"reverse_string\")\n    var ptr = wasm.function(\"get_result_buffer_ptr\")\n    var result = wasm.memory.seek(ptr).get_data(length)\n    return get_result_string(result)<\/pre>\n<p>\u51e6\u7406\u306e\u6d41\u308c\u3092\u307e\u3068\u3081\u307e\u3059\u3068\u3001<\/p>\n<ul>\n<li>store_* \u3092\u4f7f\u3063\u3066\u30c7\u30fc\u30bf\u3092 Wasm \u30e1\u30e2\u30ea\u306b\u8ee2\u9001\u3059\u308b\u3002<\/li>\n<li>\u751f\u306e\u5165\u529b\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f get_data_ptr() \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<li>\u51e6\u7406\u7d50\u679c\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f get_result_buffer_ptr() \u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/li>\n<li>BUFFER\u306f\u751f\u306e\u5165\u529b\u7528\u3001RESULT_BUFFER\u306f\u5909\u63db\u7528<\/li>\n<li>JSON\u306f\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u308f\u308c\u3001\u53d6\u5f97\u5f8c\u306b\u89e3\u6790\u3055\u308c\u308b\u3002<\/li>\n<\/ul>\n<p>\u3068\u8a00\u3063\u305f\u5f62\u3067\u3001\u69d8\u3005\u306a\u30c7\u30fc\u30bf\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092WASM\u306b\u9001\u4fe1\u30fb\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3067\u3057\u305f\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u3002<\/p>\n<p>\u307e\u305f\u307e\u305f\u3041\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3069\u3082\u3067\u3059\u3002 \u524d\u56de\u300cGodot 4 &amp; WebAssembly\u3067\u3001Hello WebAssembly! \u2013 godot-wasm\u300d\u306e\u8a18\u4e8b\u3092\u66f8\u304d\u307e\u3057\u305f\u304c\u3001\u3082\u3046\u3061\u3087\u3063\u3068\u8e0f\u307f\u8fbc\u3093\u3060\u5185\u5bb9\u306b\u306a\u308a\u307e\u3059\u3002 godot-wasm\u3092 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12290,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[188,371,166,37,373,355,114,118],"class_list":["post-12300","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-godot","tag-game","tag-godot","tag-iphone","tag-iphone-","tag-wasm","tag-webassembly","tag-114","tag-118"],"_links":{"self":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/12300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12300"}],"version-history":[{"count":3,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/12300\/revisions"}],"predecessor-version":[{"id":12305,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/posts\/12300\/revisions\/12305"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=\/wp\/v2\/media\/12290"}],"wp:attachment":[{"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcyou.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}