diff options
Diffstat (limited to 'src/intercopycontext.h')
-rw-r--r-- | src/intercopycontext.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/intercopycontext.h b/src/intercopycontext.h new file mode 100644 index 0000000..28e1ead --- /dev/null +++ b/src/intercopycontext.h | |||
@@ -0,0 +1,77 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include "tools.h" | ||
4 | |||
5 | // forwards | ||
6 | class Universe; | ||
7 | |||
8 | // ################################################################################################# | ||
9 | |||
10 | enum class VT | ||
11 | { | ||
12 | NORMAL, // keep this one first so that it's the value we get when we default-construct | ||
13 | KEY, | ||
14 | METATABLE | ||
15 | }; | ||
16 | |||
17 | enum class InterCopyResult | ||
18 | { | ||
19 | Success, | ||
20 | NotEnoughValues, | ||
21 | Error | ||
22 | }; | ||
23 | |||
24 | // ################################################################################################# | ||
25 | |||
26 | using CacheIndex = Unique<int>; | ||
27 | using SourceIndex = Unique<int>; | ||
28 | class InterCopyContext | ||
29 | { | ||
30 | public: | ||
31 | Universe* const U; | ||
32 | DestState const L2; | ||
33 | SourceState const L1; | ||
34 | CacheIndex const L2_cache_i; | ||
35 | SourceIndex L1_i; // that one can change when we reuse the context | ||
36 | VT vt; // that one can change when we reuse the context | ||
37 | LookupMode const mode; | ||
38 | char const* name; // that one can change when we reuse the context | ||
39 | |||
40 | private: | ||
41 | // when mode == LookupMode::FromKeeper, L1 is a keeper state and L2 is not, therefore L2 is the state where we want to raise the error | ||
42 | // whon mode != LookupMode::FromKeeper, L1 is not a keeper state, therefore L1 is the state where we want to raise the error | ||
43 | lua_State* getErrL() const { return (mode == LookupMode::FromKeeper) ? L2 : L1; } | ||
44 | |||
45 | // for use in copy_cached_func | ||
46 | void copy_func() const; | ||
47 | void lookup_native_func() const; | ||
48 | |||
49 | // for use in inter_copy_function | ||
50 | void copy_cached_func() const; | ||
51 | [[nodiscard]] bool lookup_table() const; | ||
52 | |||
53 | // for use in inter_copy_table | ||
54 | void inter_copy_keyvaluepair() const; | ||
55 | [[nodiscard]] bool push_cached_metatable() const; | ||
56 | [[nodiscard]] bool push_cached_table() const; | ||
57 | |||
58 | // for use in inter_copy_userdata | ||
59 | [[nodiscard]] bool tryCopyClonable() const; | ||
60 | [[nodiscard]] bool tryCopyDeep() const; | ||
61 | |||
62 | // copying a single Lua stack item | ||
63 | [[nodiscard]] bool inter_copy_boolean() const; | ||
64 | [[nodiscard]] bool inter_copy_function() const; | ||
65 | [[nodiscard]] bool inter_copy_lightuserdata() const; | ||
66 | [[nodiscard]] bool inter_copy_nil() const; | ||
67 | [[nodiscard]] bool inter_copy_number() const; | ||
68 | [[nodiscard]] bool inter_copy_string() const; | ||
69 | [[nodiscard]] bool inter_copy_table() const; | ||
70 | [[nodiscard]] bool inter_copy_userdata() const; | ||
71 | |||
72 | public: | ||
73 | [[nodiscard]] bool inter_copy_one() const; | ||
74 | [[nodiscard]] InterCopyResult inter_copy_package() const; | ||
75 | [[nodiscard]] InterCopyResult inter_copy(int n_) const; | ||
76 | [[nodiscard]] InterCopyResult inter_move(int n_) const; | ||
77 | }; | ||