Add Lua API for promises and async coroutines

This adds a Lua API for representing asynchronous operations and running
coroutines based on those operations comfortably. This is very similar
to features other languages have introduced such as C# or JavaScript. In
fact, the whole "promise" thing is derived from how JavaScript
represents these operations.

This is the initial and very basic system for supporting async
coroutines in Lua. There is no native support for running these
operations at specific points (they run whenever the awaited promise
resolved) or making sure they do not leak through different game states.
This commit is contained in:
asarium committed 2020-05-24 12:36:01 +02:00
1 parent 96bee4a4fa
commit ebcf686cf7
40 files changed
+1342 -123

No files matched your search

+7
View File
@@ -1,6 +1,8 @@
#include "scripting/scripting.h"
#include "scripting/lua/LuaUtil.h"
/**
* IMPORTANT!
*
@@ -34,6 +36,7 @@
#include "scripting/api/objs/model_path.h"
#include "scripting/api/objs/physics_info.h"
#include "scripting/api/objs/player.h"
#include "scripting/api/objs/promise.h"
#include "scripting/api/objs/sexpvar.h"
#include "scripting/api/objs/shields.h"
#include "scripting/api/objs/ship.h"
@@ -55,6 +58,7 @@
#include "scripting/api/objs/wing.h"
#include "scripting/api/libs/audio.h"
#include "scripting/api/libs/async.h"
#include "scripting/api/libs/base.h"
#include "scripting/api/libs/bitops.h"
#include "scripting/api/libs/cfile.h"
@@ -108,6 +112,9 @@ int script_state::CreateLuaState()
mprintf(("LUA: Initializing base Lua libraries...\n"));
luaL_openlibs(L);
//*****INITIALIZE OUR SUPPORT LIBRARY
luacpp::util::initializeLuaSupportLib(L);
//*****DISABLE DANGEROUS COMMANDS
lua_pushstring(L, "os");
lua_rawget(L, LUA_GLOBALSINDEX);