Skip to content

Commit

Permalink
add version string to webasm page
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Jan 14, 2019
1 parent b129363 commit 809d72f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions run_local_server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
where /q http-server

IF ERRORLEVEL 1 (npm i -g http-server)

http-server -p 80
1 change: 0 additions & 1 deletion run_local_webasm_server.bat

This file was deleted.

7 changes: 7 additions & 0 deletions src/webasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ pub unsafe extern fn wasm_assemble(format: u32, src: *mut String) -> *mut String
}


#[no_mangle]
pub unsafe extern fn wasm_get_version() -> *mut String
{
wasm_string_new_with(env!("CARGO_PKG_VERSION"))
}


#[no_mangle]
pub unsafe extern fn wasm_string_new(len: u32) -> *mut String
{
Expand Down
1 change: 1 addition & 0 deletions webasm/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<option>Bin String</option>
</select>
<button id="buttonAssemble" onclick="assemble()" disabled>Assemble (Ctrl+Enter) &gt;&gt;</button>
<span id="spanVersion"></span>
<a href="https://github.com/hlorenzi/customasm">GitHub Repository</a>
</div>
<div id="divOutput">
Expand Down
21 changes: 20 additions & 1 deletion webasm/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ function main()
onResize()

document.body.onresize = onResize
window.onresize = onResize
window.onkeydown = onKeyDown
window.onbeforeunload = onBeforeUnload

Expand All @@ -19,6 +18,7 @@ function main()
{
g_wasm = wasm
document.getElementById("buttonAssemble").disabled = false
setupVersionString()
})
}

Expand All @@ -39,6 +39,25 @@ function setupEditor()
}


function setupVersionString()
{
let outputPtr = null
try
{
outputPtr = g_wasm.instance.exports.wasm_get_version()
}
catch (e)
{
throw e
}

let output = readRustString(outputPtr)
dropRustString(outputPtr)

document.getElementById("spanVersion").innerHTML = "v" + output
}


function onResize()
{
let rectInput = document.getElementById("divCodeMirror").getBoundingClientRect()
Expand Down

0 comments on commit 809d72f

Please sign in to comment.