Browse Source

Platform: ability to pass command-line args to Emscripten browser apps.

pull/217/head
Vladimír Vondruš 9 years ago
parent
commit
215beaa3be
  1. 3
      doc/changelog.dox
  2. 16
      src/Magnum/Platform/EmscriptenApplication.js
  3. 4
      src/Magnum/Platform/Sdl2Application.h
  4. 4
      src/Magnum/Platform/WindowlessEglApplication.h
  5. 16
      src/Magnum/Platform/WindowlessEmscriptenApplication.js

3
doc/changelog.dox

@ -260,6 +260,9 @@ namespace Magnum {
- Added @ref Platform::Sdl2Application::KeyEvent::keyName() "Platform::*Application::KeyEvent::keyName()" - Added @ref Platform::Sdl2Application::KeyEvent::keyName() "Platform::*Application::KeyEvent::keyName()"
- It's now possible to iterate main loop manually using - It's now possible to iterate main loop manually using
@ref Platform::Sdl2Application::mainLoopIteration() @ref Platform::Sdl2Application::mainLoopIteration()
- Ability to pass command-line arguments to Emscripten browser apps, see
@ref Platform::Sdl2Application and @ref Platform::WindowlessEglApplication
for more information
### Primitives library ### Primitives library

16
src/Magnum/Platform/EmscriptenApplication.js

@ -2,6 +2,8 @@ var Module = {
preRun: [], preRun: [],
postRun: [], postRun: [],
arguments: [],
printErr: function(message) { printErr: function(message) {
console.error(Array.prototype.slice.call(arguments).join(' ')); console.error(Array.prototype.slice.call(arguments).join(' '));
}, },
@ -37,6 +39,20 @@ var Module = {
} }
}; };
/* Parse arguments, e.g. /app/?foo=bar&fizz&buzz=3 goes to the app as
['--foo', 'bar', '--fizz', '--buzz', '3'] */
var args = decodeURIComponent(window.location.search.substr(1)).trim().split('&');
for(var i = 0; i != args.length; ++i) {
var j = args[i].indexOf('=');
/* Key + value */
if(j != -1) {
Module.arguments.push('--' + args[i].substring(0, j));
Module.arguments.push(args[i].substring(j + 1));
/* Just key */
} else Module.arguments.push('--' + args[i]);
}
Module.setStatus('Downloading...'); Module.setStatus('Downloading...');
Module.canvas.addEventListener('contextmenu', function(event) { Module.canvas.addEventListener('contextmenu', function(event) {

4
src/Magnum/Platform/Sdl2Application.h

@ -229,7 +229,9 @@ The CSS file contains rudimentary style to avoid eye bleeding.
The application redirects all output (thus also @ref Corrade::Utility::Debug "Debug", The application redirects all output (thus also @ref Corrade::Utility::Debug "Debug",
@ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error") @ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error")
to JavaScript console. to JavaScript console. It's possible to pass command-line arguments to `main()`
using GET URL parameters. For example, `/app/?foo=bar&fizz&buzz=3` will go to
the app as `['--foo', 'bar', '--fizz', '--buzz', '3']`.
## Usage with iOS ## Usage with iOS

4
src/Magnum/Platform/WindowlessEglApplication.h

@ -298,7 +298,9 @@ The CSS file contains rudimentary style to avoid eye bleeding.
The application prints all output (thus also @ref Corrade::Utility::Debug "Debug", The application prints all output (thus also @ref Corrade::Utility::Debug "Debug",
@ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error") @ref Corrade::Utility::Warning "Warning" and @ref Corrade::Utility::Error "Error")
to the `<pre>` on the page. to the `<pre>` on the page. It's possible to pass command-line arguments
to `main()` using GET URL parameters. For example, `/app/?foo=bar&fizz&buzz=3`
will go to the app as `['--foo', 'bar', '--fizz', '--buzz', '3']`.
*/ */
class WindowlessEglApplication { class WindowlessEglApplication {
public: public:

16
src/Magnum/Platform/WindowlessEmscriptenApplication.js

@ -2,6 +2,8 @@ var Module = {
preRun: [], preRun: [],
postRun: [], postRun: [],
arguments: [],
printErr: function(message) { printErr: function(message) {
var log = document.getElementById('log'); var log = document.getElementById('log');
log.innerHTML += Array.prototype.slice.call(arguments).join(' ') + '\n'; log.innerHTML += Array.prototype.slice.call(arguments).join(' ') + '\n';
@ -39,6 +41,20 @@ var Module = {
} }
}; };
/* Parse arguments, e.g. /app/?foo=bar&fizz&buzz=3 goes to the app as
['--foo', 'bar', '--fizz', '--buzz', '3'] */
var args = decodeURIComponent(window.location.search.substr(1)).trim().split('&');
for(var i = 0; i != args.length; ++i) {
var j = args[i].indexOf('=');
/* Key + value */
if(j != -1) {
Module.arguments.push('--' + args[i].substring(0, j));
Module.arguments.push(args[i].substring(j + 1));
/* Just key */
} else Module.arguments.push('--' + args[i]);
}
Module.setStatus('Downloading...'); Module.setStatus('Downloading...');
Module.canvas.addEventListener('contextmenu', function(event) { Module.canvas.addEventListener('contextmenu', function(event) {

Loading…
Cancel
Save