diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-05-03 04:48:17 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-05-03 04:48:17 +0000 |
| commit | 3ceb8025ee4330c177101ed30ec17dfb0002f41e (patch) | |
| tree | 58350210f15df7d00d967cac6f30eeceeb031a3c /src/tangara/lua/lua_thread.hpp | |
| parent | 964da15a0b84f8e5f00e8abac2f7dfda0bf60488 (diff) | |
| parent | 9fafd797a5504f458b5fcae4a1d28a68da936315 (diff) | |
| download | tangara-fw-3ceb8025ee4330c177101ed30ec17dfb0002f41e.tar.gz | |
Merge pull request 'Break dependency cycles with our components by merging co-dependent components together' (#68) from jqln/component-merge into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/68
Diffstat (limited to 'src/tangara/lua/lua_thread.hpp')
| -rw-r--r-- | src/tangara/lua/lua_thread.hpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/tangara/lua/lua_thread.hpp b/src/tangara/lua/lua_thread.hpp new file mode 100644 index 00000000..d7602c1e --- /dev/null +++ b/src/tangara/lua/lua_thread.hpp @@ -0,0 +1,44 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#pragma once + +#include <memory> +#include <string> + +#include "lua.hpp" + +#include "system_fsm/service_locator.hpp" + +namespace lua { + +class Allocator; + +auto CallProtected(lua_State*, int nargs, int nresults) -> int; + +class LuaThread { + public: + static auto Start(system_fsm::ServiceLocator&) -> LuaThread*; + ~LuaThread(); + + auto RunScript(const std::string& path) -> bool; + auto RunString(const std::string& path) -> bool; + + auto DumpStack() -> void; + + auto state() -> lua_State* { return state_; } + + LuaThread(const LuaThread&) = delete; + LuaThread& operator=(const LuaThread&) = delete; + + private: + LuaThread(std::unique_ptr<Allocator>&, lua_State*); + + std::unique_ptr<Allocator> alloc_; + lua_State* state_; +}; + +} // namespace lua |
