Context.h
1/* Copyright (C) 2020-2026 by Marc Boris Duerner
2 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
3*/
4
5#ifndef PT_LUA_CONTEXT_H
6#define PT_LUA_CONTEXT_H
7
8#include <Pt/Lua/Api.h>
9#include <Pt/Lua/AsyncCall.h>
10#include <Pt/Reflex/TypeManager.h>
11#include <Pt/Any.h>
12
13#include <map>
14#include <string>
15#include <vector>
16
17struct lua_State;
18
19namespace Pt {
20
21namespace Lua {
22
52class PT_LUA_API Context
53{
54 public:
60 explicit Context(Pt::Reflex::TypeManager& tm);
61
65
68 lua_State* state() const
69 { return _L; }
70
73 Pt::Reflex::TypeManager& typeManager()
74 { return _tm; }
75
78 void reset();
79
80 private:
81 Context(const Context&);
82
83 Context& operator=(const Context&);
84
85 void bindType(Pt::Reflex::Type& type);
86
87 void bindFunction(Pt::Reflex::FunctionInfo& function);
88
89 void bind(Pt::Reflex::TypeManager& tm);
90
91 bool hasStandardGlobal(const std::string& name) const;
92
93 private:
94 Pt::Reflex::TypeManager& _tm;
95 struct lua_State* _L;
96 std::map<std::string, void*> _bindings;
97 std::vector<std::string> _standardGlobals;
98};
99
102struct LuaObjectHeader
103{
104 void* instance;
105 Pt::Reflex::Type* type;
106};
107
110static const std::size_t LUAOBJECT_DATA_OFFSET =
111 (sizeof(LuaObjectHeader) + sizeof(void*) - 1) & ~(sizeof(void*) - 1);
112
113} // namespace
114
115} // namespace
116
117#endif // include guard
lua_State * state() const
Returns the Lua state of this context.
Definition Context.h:68
Context(Pt::Reflex::TypeManager &tm)
Creates a Lua state and binds tm.
Pt::Reflex::TypeManager & typeManager()
Returns the type manager this context bound.
Definition Context.h:73
void reset()
Removes script-created globals and collects garbage.
~Context()
Closes the Lua state.
Lua runtime and reflected bindings.
Core module.
Definition Allocator.h:33