diff --git a/cart/as/README.md b/cart/as/README.md index 4040be8..a472bad 100644 --- a/cart/as/README.md +++ b/cart/as/README.md @@ -1,5 +1,7 @@ This is an example null0 cart written in [assemblyscript](https://www.assemblyscript.org/). +You can make your own by editing files in [src/](src). `npm run build` will build your cart in `build/`. Change the package-name in package.json to change the name of the cart. + ## TODO -- look into [better build](https://github.com/notnullgames/null0-ideas/blob/main/projects/assemblyscript/tools/build.mjs) +- look into [better cross-plaform build](https://github.com/notnullgames/null0-ideas/blob/main/projects/assemblyscript/tools/build.mjs) diff --git a/cart/as/asconfig.json b/cart/as/asconfig.json deleted file mode 100644 index b72c80b..0000000 --- a/cart/as/asconfig.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "targets": { - "release": { - "outFile": "build/main.wasm", - "textFile": "build/main.wat", - "sourceMap": true, - "optimizeLevel": 3, - "shrinkLevel": 0, - "converge": false, - "noAssert": false - } - }, - "options": { - "bindings": "esm" - } -} diff --git a/cart/as/null0.ts b/cart/as/null0.ts index 4fea8ba..6f93cd4 100644 --- a/cart/as/null0.ts +++ b/cart/as/null0.ts @@ -1,22 +1,2 @@ // include this in your null0 cart -// asc src/index.ts --target release --use trace=_null0_trace --use abort=_null0_abort --use seed=_null0_seed --lib ./null0.ts - -// log a string -@external("null0", "trace") -declare function _null0_real_trace(text: ArrayBuffer): void - -// these are called by language -// https://www.assemblyscript.org/concepts.html#special-imports -// TODO: would WASI help with these? - -export function _null0_trace(message: String): void { - _null0_real_trace(String.UTF8.encode(message, true)); -} - -export function _null0_abort(message: String, fileName: String, line: u32, column: u32): void { - _null0_real_trace(String.UTF8.encode("ABORT: " + message, true)); -} - -export function _null0_seed(): f64 { - return 1.0; -} +// asc --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --lib ./null0.ts src/main.ts diff --git a/cart/as/package-lock.json b/cart/as/package-lock.json index eddbf24..a3c4f00 100644 --- a/cart/as/package-lock.json +++ b/cart/as/package-lock.json @@ -1,17 +1,29 @@ { - "name": "@null0/example-as", + "name": "example-as", "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "@null0/example-as", + "name": "example-as", "version": "0.0.0", "license": "MIT", "devDependencies": { + "@assemblyscript/wasi-shim": "^0.1.0", "assemblyscript": "^0.27.29" } }, + "node_modules/@assemblyscript/wasi-shim": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@assemblyscript/wasi-shim/-/wasi-shim-0.1.0.tgz", + "integrity": "sha512-fSLH7MdJHf2uDW5llA5VCF/CG62Jp2WkYGui9/3vIWs3jDhViGeQF7nMYLUjpigluM5fnq61I6obtCETy39FZw==", + "dev": true, + "license": "Apache-2.0", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/assemblyscript" + } + }, "node_modules/assemblyscript": { "version": "0.27.29", "resolved": "https://registry.npmjs.org/assemblyscript/-/assemblyscript-0.27.29.tgz", diff --git a/cart/as/package.json b/cart/as/package.json index e5f987c..0322ab0 100644 --- a/cart/as/package.json +++ b/cart/as/package.json @@ -1,13 +1,16 @@ { - "name": "@null0/example-as", + "name": "example-as", + "private": true, "version": "0.0.0", "scripts": { - "build": "asc src/index.ts --exportStart=_null0_init --target release --use trace=_null0_trace --use abort=_null0_abort --use seed=_null0_seed --lib ./null0.ts && mkdir -p build/cart/assets && cp build/main.wasm build/cart && cp src/assets/* build/cart/assets && cd build/cart && zip -r ../example.null0 .", - "start": "../../build/host/null0 ./build/example.null0", + "build": "asc --config ./node_modules/@assemblyscript/wasi-shim/asconfig.json --lib ./null0.ts --optimizeLevel 3 --outFile build/cart/main.wasm src/main.ts", + "postbuild": "mkdir -p build/cart/assets && cp src/assets/* build/cart/assets && cd build/cart && zip -r ../${npm_package_name}.null0 . && cp ../${npm_package_name}.null0 ../../../../docs/cart/", + "start": "../../build/host/null0 ./build/${npm_package_name}.null0", "prestart": "npm run build" }, "license": "MIT", "devDependencies": { + "@assemblyscript/wasi-shim": "^0.1.0", "assemblyscript": "^0.27.29" }, "type": "module", diff --git a/cart/as/src/index.ts b/cart/as/src/main.ts similarity index 69% rename from cart/as/src/index.ts rename to cart/as/src/main.ts index 8fdc3bc..5fe29d6 100644 --- a/cart/as/src/index.ts +++ b/cart/as/src/main.ts @@ -1,9 +1,9 @@ // called when the cart is loaded export function load(): void { - trace("hello from AS"); + console.log("hello from AS"); } // called on every frame export function update(): void { - trace("update"); + console.log("update"); } diff --git a/cart/as/src/tsconfig.json b/cart/as/tsconfig.json similarity index 58% rename from cart/as/src/tsconfig.json rename to cart/as/tsconfig.json index e28fcf2..4a6705d 100644 --- a/cart/as/src/tsconfig.json +++ b/cart/as/tsconfig.json @@ -1,6 +1,4 @@ { "extends": "assemblyscript/std/assembly.json", - "include": [ - "./**/*.ts" - ] -} \ No newline at end of file + "include": ["./src/**/*.ts"] +} diff --git a/docs/cart/example-as.null0 b/docs/cart/example-as.null0 new file mode 100644 index 0000000..7efa633 Binary files /dev/null and b/docs/cart/example-as.null0 differ diff --git a/docs/null0.js b/docs/null0.js index 547f560..1623a5c 100755 --- a/docs/null0.js +++ b/docs/null0.js @@ -134,10 +134,6 @@ export async function setupCart( out.cart = cart; - if (cart._null0_init) { - cart._null0_init(); - } - if (cart._start) { cart._start(); } diff --git a/null0_api/src/null0_api_wamr.h b/null0_api/src/null0_api_wamr.h index aaaab30..7ae8080 100755 --- a/null0_api/src/null0_api_wamr.h +++ b/null0_api/src/null0_api_wamr.h @@ -833,13 +833,13 @@ bool null0_init() { cart_keyUp = wasm_runtime_lookup_function(module_inst, "keyUp"); cart_keyDown = wasm_runtime_lookup_function(module_inst, "keyDown"); - // this is for AS, since it needs a seperate function called + // this is for hosts that seperate init wasm_function_inst_t cart_init = NULL; - cart_init = wasm_runtime_lookup_function(module_inst, "_null0_init"); + cart_init = wasm_runtime_lookup_function(module_inst, "load"); if (cart_init != NULL) { if (!wasm_runtime_call_wasm(exec_env, cart_init, 0, NULL)) { // not fatal, but this will help with troubleshooting - printf("init: %s\n", wasm_runtime_get_exception(module_inst)); + printf("load: %s\n", wasm_runtime_get_exception(module_inst)); } }