-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sample code to run in the browser. * Added way to extract command output and store it in a string. * Working on getting bundled javascript to work. * Tinkering * Tinkering with bundling. * Got bundled version to run. * Adding index file.
- Loading branch information
1 parent
b0ce185
commit f6822dc
Showing
7 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import gwFactory from './gnollwasm.js'; | ||
|
||
export async function roll(notation) { | ||
return new Promise((resolve) => { | ||
gwFactory().then((Module) => { | ||
Module.resetOut(); | ||
|
||
Module.ccall('roll_full_options', 'number', ['string', | ||
'string', 'number', 'number', 'number', 'number', 'number', | ||
'number'], | ||
[notation, null, 0, 0, 0, 1, 0, 0] | ||
); | ||
|
||
resolve( Module.stdout ); | ||
}); | ||
|
||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<html> | ||
<head> | ||
<title>Sample App</title> | ||
|
||
<script src="gnoll.bundle.js"></script> | ||
<script> | ||
async function onRoll() { | ||
var notation = document.getElementById("tbNotation"); | ||
var output = document.getElementById("output"); | ||
|
||
await gnoll.roll(notation.value).then(result => output.innerHTML = result); | ||
} | ||
</script> | ||
</head> | ||
<body> | ||
<div> | ||
<p>Input: <input type="text" id="tbNotation" /></p> | ||
<p><button onclick="onRoll()">Roll</button></p> | ||
</div> | ||
<div id="output"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "GNOLL", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"webpack": "^5.91.0", | ||
"webpack-cli": "^5.1.4" | ||
}, | ||
"dependencies": { | ||
"browserify-fs": "^1.0.0", | ||
"buffer": "^6.0.3", | ||
"crypto-browserify": "^3.12.0", | ||
"path-browserify": "^1.0.1", | ||
"stream-browserify": "^3.0.0", | ||
"util": "^0.12.5", | ||
"vm-browserify": "^1.1.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var Module = { | ||
stdout : "", | ||
resetOut: function() { Module.stdout = ""; }, | ||
print: function(text) { Module.stdout += text; }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
mode: 'development', | ||
entry: { | ||
wrapper: { | ||
import: './gnoll.js', | ||
}, | ||
}, | ||
node: { | ||
global: true, | ||
__filename: true, | ||
__dirname: true, | ||
}, | ||
resolve: { | ||
fallback: { | ||
fs: require.resolve('browserify-fs'), | ||
path: require.resolve('path-browserify'), | ||
buffer: require.resolve('buffer'), | ||
stream: require.resolve('stream-browserify'), | ||
crypto: require.resolve("crypto-browserify"), | ||
vm: require.resolve("vm-browserify") | ||
} | ||
}, | ||
devtool: 'source-map', | ||
output: { | ||
filename: 'gnoll.bundle.js', | ||
path: path.resolve(__dirname, '../../build/jsweb/'), | ||
library: 'gnoll' | ||
}, | ||
experiments: { | ||
asyncWebAssembly: true, | ||
syncWebAssembly: true | ||
}, | ||
devServer: { | ||
static: { | ||
directory: path.join(__dirname, 'dist'), | ||
}, | ||
compress: true, | ||
port: 9000 | ||
}, | ||
} |