{"id":18790672,"url":"https://github.com/onsails/wasmer-as","last_synced_at":"2025-09-05T03:34:00.183Z","repository":{"id":45282011,"uuid":"234827751","full_name":"onsails/wasmer-as","owner":"onsails","description":"Helpers for dealing with assemblyscript memory inside wasmer-runtime","archived":false,"fork":false,"pushed_at":"2022-12-13T02:01:22.000Z","size":62,"stargazers_count":23,"open_issues_count":3,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-13T14:13:07.460Z","etag":null,"topics":["assemblyscript","typescript","wasm","wasmer","webassembly"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onsails.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-19T02:25:07.000Z","updated_at":"2024-08-16T09:00:41.000Z","dependencies_parsed_at":"2023-01-28T04:45:58.658Z","dependency_job_id":null,"html_url":"https://github.com/onsails/wasmer-as","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fwasmer-as","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fwasmer-as/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fwasmer-as/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onsails%2Fwasmer-as/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onsails","download_url":"https://codeload.github.com/onsails/wasmer-as/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248724628,"owners_count":21151561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assemblyscript","typescript","wasm","wasmer","webassembly"],"created_at":"2024-11-07T21:13:13.806Z","updated_at":"2025-04-13T14:13:12.630Z","avatar_url":"https://github.com/onsails.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"Helpers for dealing with assemblyscript memory inside wasmer-runtime\n===\n\n```rust\nuse std::error::Error;\nuse wasmer::*;\nuse wasmer_as::{AsmScriptRead, AsmScriptStringPtr};\n\n#[derive(Clone)]\nstruct Env {\n    memory: LazyInit\u003cMemory\u003e,\n}\n\nimpl WasmerEnv for Env {\n    fn init_with_instance(\u0026mut self, instance: \u0026Instance) -\u003e Result\u003c(), HostEnvInitError\u003e {\n        self.memory.initialize(\n            instance\n                .exports\n                .get_memory(\"memory\")\n                .map_err(HostEnvInitError::from)?\n                .clone(),\n        );\n        Ok(())\n    }\n}\n\nfn main() -\u003e Result\u003c(), Box\u003cdyn Error\u003e\u003e {\n    let wasm_bytes = include_bytes!(concat!(\n        env!(\"CARGO_MANIFEST_DIR\"),\n        \"/test-wasm/build/optimized.wasm\"\n    ));\n    let store = Store::default();\n    let module = Module::new(\u0026store, wasm_bytes)?;\n\n    let env = Env {\n        memory: LazyInit::default(),\n    };\n\n    let import_object = imports! {\n        \"env\" =\u003e {\n            \"abort\" =\u003e Function::new_native_with_env(\u0026store, env, abort),\n        },\n    };\n\n    let instance = Instance::new(\u0026module, \u0026import_object)?;\n\n    // for the test we use simple function returning constant string:\n    //\n    // export function getString(): string {\n    //   return \"TheString\";\n    // }\n    let get_string = instance.exports.get_function(\"getString\")?;\n\n    let results = get_string.call(\u0026[])?;\n\n    let str_ptr = results.first().expect(\"get pointer\");\n    let str_ptr = AsmScriptStringPtr::new(str_ptr.unwrap_i32() as u32);\n\n    let memory = instance.exports.get_memory(\"memory\").expect(\"get memory\");\n    let string = str_ptr.read(memory)?;\n\n    assert_eq!(string, \"$¢ह한𝌆\");\n\n    Ok(())\n}\n\n// if get_string throws an exception abort for some reason is being called\nfn abort(\n    env: \u0026Env,\n    message: AsmScriptStringPtr,\n    filename: AsmScriptStringPtr,\n    line: i32,\n    col: i32\n) {\n    let memory = env.memory.get_ref().expect(\"initialized memory\");\n    let message = message.read(memory).unwrap();\n    let filename = filename.read(memory).unwrap();\n    eprintln!(\"Error: {} at {}:{} col: {}\", message, filename, line, col);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsails%2Fwasmer-as","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonsails%2Fwasmer-as","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonsails%2Fwasmer-as/lists"}