Update jerryscript each frame.
This commit is contained in:
+10
-6
@@ -10,12 +10,16 @@ const platformNames = {
|
||||
|
||||
Console.print('Platform: ' + (platformNames[System.platform] || 'Unknown'));
|
||||
|
||||
const test = require('test.js');
|
||||
Console.print(test.str());
|
||||
test.increment();
|
||||
Console.print(test.str());
|
||||
test.decrement();
|
||||
Console.print(test.str());
|
||||
// Testing async/await
|
||||
async function testAsync() {
|
||||
Console.print('Testing async/await...');
|
||||
await new Promise(resolve => requestAnimationFrame(resolve));
|
||||
Console.print('First await done!');
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
Console.print('Async/await works!');
|
||||
}
|
||||
|
||||
testAsync();
|
||||
|
||||
// Scene.set('testscene.js');
|
||||
// Console.print('Loading scene...');
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
Console.print('test included');
|
||||
|
||||
var x = 1 + 2;
|
||||
|
||||
module.exports = {
|
||||
str: function() {
|
||||
return x.toString();
|
||||
},
|
||||
increment: function() {
|
||||
x++;
|
||||
},
|
||||
decrement: function() {
|
||||
x--;
|
||||
}
|
||||
}
|
||||
@@ -78,6 +78,7 @@ errorret_t engineUpdate(void) {
|
||||
errorChain(cutsceneUpdate());
|
||||
sceneUpdate();
|
||||
errorChain(assetUpdate());
|
||||
errorChain(scriptUpdate());
|
||||
|
||||
if(inputPressed(INPUT_ACTION_RAGEQUIT)) ENGINE.running = false;
|
||||
errorOk();
|
||||
|
||||
@@ -27,6 +27,27 @@ errorret_t scriptInit(void) {
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t scriptUpdate() {
|
||||
jerry_value_t ret = jerry_run_jobs();
|
||||
|
||||
if(jerry_value_is_exception(ret)) {
|
||||
char_t buf[256];
|
||||
jerry_value_t errVal = jerry_exception_value(ret, false);
|
||||
jerry_value_t errStr = jerry_value_to_string(errVal);
|
||||
jerry_size_t len = jerry_string_to_buffer(
|
||||
errStr, JERRY_ENCODING_UTF8, (jerry_char_t *)buf, sizeof(buf) - 1
|
||||
);
|
||||
buf[len] = '\0';
|
||||
jerry_value_free(errStr);
|
||||
jerry_value_free(errVal);
|
||||
jerry_value_free(ret);
|
||||
errorThrow("Script error: %s", buf);
|
||||
}
|
||||
|
||||
jerry_value_free(ret);
|
||||
errorOk();
|
||||
}
|
||||
|
||||
errorret_t scriptExecString(const char_t *source) {
|
||||
assertNotNull(source, "Source cannot be NULL");
|
||||
assertTrue(SCRIPT.initialized, "Script system not initialized");
|
||||
|
||||
@@ -22,6 +22,14 @@ extern script_t SCRIPT;
|
||||
*/
|
||||
errorret_t scriptInit(void);
|
||||
|
||||
/**
|
||||
* Updates the script system, running any pending jobs. This should be called
|
||||
* once per frame.
|
||||
*
|
||||
* @return Any error that occurred.
|
||||
*/
|
||||
errorret_t scriptUpdate(void);
|
||||
|
||||
/**
|
||||
* Evaluates a JS source string in the global scope.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user