forked from WeaselGames/godot_luaAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathluaAPI.h
More file actions
106 lines (77 loc) · 2.23 KB
/
Copy pathluaAPI.h
File metadata and controls
106 lines (77 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef LUAAPI_H
#define LUAAPI_H
#ifndef LAPI_GDEXTENSION
#include "core/core_bind.h"
#include "core/object/ref_counted.h"
#else
#include <godot_cpp/classes/ref.hpp>
#endif
#include "luaError.h"
#include <luaState.h>
#include <lua/lua.hpp>
#ifdef LAPI_GDEXTENSION
using namespace godot;
#endif
class LuaCoroutine;
class LuaObjectMetatable;
class LuaAPI : public RefCounted {
GDCLASS(LuaAPI, RefCounted);
protected:
static void _bind_methods();
public:
LuaAPI();
~LuaAPI();
void setHook(Callable hook, int mask, int count);
void setUseCallables(bool value);
bool getUseCallables() const;
void setObjectMetatable(Ref<LuaObjectMetatable> value);
Ref<LuaObjectMetatable> getObjectMetatable() const;
void setMemoryLimit(uint64_t limit);
uint64_t getMemoryLimit() const;
int configureGC(int what, int data);
uint64_t getMemoryUsage() const;
bool luaFunctionExists(String functionName);
Variant pullVariant(String name);
Variant callFunction(String functionName, Array args);
Variant doFile(String fileName, Array args);
Variant doString(String code, Array args);
Variant getRegistryValue(String name);
Ref<LuaError> setRegistryValue(String name, Variant var);
Ref<LuaError> bindLibraries(Array libs);
Ref<LuaError> pushGlobalVariant(String name, Variant var);
Ref<LuaCoroutine> newCoroutine();
Ref<LuaCoroutine> getRunningCoroutine();
lua_State *newThreadState();
lua_State *getState();
enum HookMask {
HOOK_MASK_CALL = LUA_MASKCALL,
HOOK_MASK_RETURN = LUA_MASKRET,
HOOK_MASK_LINE = LUA_MASKLINE,
HOOK_MASK_COUNT = LUA_MASKCOUNT,
};
enum GCOption {
GC_STOP = LUA_GCSTOP,
GC_RESTART = LUA_GCRESTART,
GC_COLLECT = LUA_GCCOLLECT,
GC_COUNT = LUA_GCCOUNT,
GC_COUNTB = LUA_GCCOUNTB,
GC_STEP = LUA_GCSTEP,
GC_SETPAUSE = LUA_GCSETPAUSE,
GC_SETSTEPMUL = LUA_GCSETSTEPMUL,
};
private:
bool useCallables = true;
LuaState state;
lua_State *lState = nullptr;
Ref<LuaObjectMetatable> objectMetatable;
static void *luaAlloc(void *ud, void *ptr, size_t osize, size_t nsize);
struct LuaAllocData {
uint64_t memoryUsed = 0;
uint64_t memoryLimit = 0;
};
LuaAllocData luaAllocData;
Variant execute(int argc, int handlerIndex);
};
VARIANT_ENUM_CAST(LuaAPI::HookMask)
VARIANT_ENUM_CAST(LuaAPI::GCOption)
#endif