diff options
author | Nicolas Noble <nnoble@blizzard.com> | 2013-08-05 17:05:51 -0700 |
---|---|---|
committer | Nicolas Noble <nnoble@blizzard.com> | 2013-08-05 17:05:51 -0700 |
commit | 3c1040007a354ce55bd964beabac94b67c1f6fc7 (patch) | |
tree | 237cbd6b223ab526c0b177fc28755bd7805226a4 /src | |
parent | d625e8c12de02e2c39d687b735e6e8d5a3fd0865 (diff) |
Adding the LuaLoad function.
Diffstat (limited to 'src')
-rw-r--r-- | src/LuaLoad.cc | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/LuaLoad.cc b/src/LuaLoad.cc new file mode 100644 index 0000000..de7501f --- /dev/null +++ b/src/LuaLoad.cc @@ -0,0 +1,64 @@ +#include "LuaLoad.h" +#include "LuaTask.h" +#include "Buffer.h" +#include "Input.h" + +using namespace Balau; + +namespace { + +class LuaLoad { }; + +enum LuaLoad_functions_t { + LUALOAD +}; + +struct lua_functypes_t LuaLoad_functions[] = { + { LUALOAD, "load", 1, 1, { BLUA_OBJECT | BLUA_STRING } }, + { -1, 0, 0, 0, 0 } +}; + +struct sLua_LuaLoad { + static int LuaLoad_proceed_static(Lua & L, int n, int caller) { + IO<Handle> h; + enum { + OPENING, + CREATETASK, + WAITTASK, + } status; + if (L.isobject()) { + h = L.recast<Handle>(); + if (h.isA<Buffer>()) { + L.load(h); + return 0; + } + status = CREATETASK; + } else { + h = new Input(L.tostring()); + status = OPENING; + } + LuaExecFile * execFile = NULL; + return L.yield(Future<int>([L, status, h, execFile]() mutable { + switch (status) { + case OPENING: + h.asA<Input>()->open(); + status = CREATETASK; + case CREATETASK: + execFile = new LuaExecFile(h); + status = WAITTASK; + execFile->exec(L); + case WAITTASK: + execFile->throwError(); // will induce a memory leak in case of an actual error. + delete execFile; + } + return 0; + })); + } +}; + +}; + +void registerLuaLoad(Lua & L) { + CHECK_FUNCTIONS(LuaLoad); + PUSH_FUNCTION(LuaLoad, LUALOAD); +} |