Skip to content

Commit 1692d2e

Browse files
authored
Merge pull request #74 from Legacy-LuaSTG-Engine/feature/update-imgui-3
[Feature] Going to imgui 1.92.1
2 parents eb3c0c8 + 8d55feb commit 1692d2e

101 files changed

Lines changed: 7709 additions & 10746 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ include(LuaSTG/shaders.cmake)
2929
add_subdirectory(imgui)
3030

3131
add_subdirectory(engine)
32+
target_link_libraries(lua_imgui PUBLIC lua_plus) # TODO: 丑不拉几的
3233
add_subdirectory(tool)
3334
add_subdirectory(LuaSTG)
3435

LuaSTG/LuaSTG/Custom/resource.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ END
5050
//
5151

5252
VS_VERSION_INFO VERSIONINFO
53-
FILEVERSION 0,21,107,0
54-
PRODUCTVERSION 0,21,107,0
53+
FILEVERSION 0,21,108,0
54+
PRODUCTVERSION 0,21,108,0
5555
FILEFLAGSMASK 0x3fL
5656
#ifdef _DEBUG
5757
FILEFLAGS 0x1L
@@ -68,12 +68,12 @@ BEGIN
6868
BEGIN
6969
VALUE "CompanyName", "璀境石"
7070
VALUE "FileDescription", "LuaSTG Sub"
71-
VALUE "FileVersion", "0.21.107.0"
71+
VALUE "FileVersion", "0.21.108.0"
7272
VALUE "InternalName", "LuaSTG Sub"
7373
VALUE "LegalCopyright", "Copyright 2020-2025 璀境石"
7474
VALUE "OriginalFilename", "LuaSTGSub.exe"
7575
VALUE "ProductName", "LuaSTG Sub"
76-
VALUE "ProductVersion", "0.21.107.0"
76+
VALUE "ProductVersion", "0.21.108.0"
7777
END
7878
END
7979
BLOCK "VarFileInfo"

LuaSTG/LuaSTG/Debugger/ImGuiExtension.cpp

Lines changed: 673 additions & 845 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
#pragma once
1+
#pragma once
22

3-
namespace imgui
4-
{
5-
void loadConfig();
6-
void saveConfig();
7-
8-
void bindEngine();
9-
void unbindEngine();
10-
11-
void cacheGlyphFromString(std::string_view str);
12-
void cancelSetCursor();
13-
void updateEngine(bool allow_set_cursor);
14-
void drawEngine();
3+
namespace imgui {
4+
void bindEngine();
5+
void unbindEngine();
156

16-
void showTestInputWindow(bool* p_open = nullptr);
7+
void cancelSetCursor();
8+
void updateEngine(bool allow_set_cursor);
9+
void drawEngine();
10+
11+
void showTestInputWindow(bool* p_open = nullptr);
1712
};

LuaSTG/LuaSTG/LConfig.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
#define LUASTG_NAME "LuaSTG"
44
#define LUASTG_BRANCH "Sub"
5-
#define LUASTG_VERSION_NAME "v0.21.107"
5+
#define LUASTG_VERSION_NAME "v0.21.108"
66
#define LUASTG_VERSION_MAJOR 0
77
#define LUASTG_VERSION_MINOR 21
8-
#define LUASTG_VERSION_PATCH 107
8+
#define LUASTG_VERSION_PATCH 108
99

1010
#define LUASTG_INFO LUASTG_NAME " " LUASTG_BRANCH " " LUASTG_VERSION_NAME
1111

LuaSTG/LuaSTG/LuaBinding/modern/GameObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ namespace luastg::binding {
801801
auto const table = ctx.create_array(3); // class object
802802
ctx.set_array_value(table, 1, lua::stack_index_t(1));
803803
ctx.set_array_value(table, 2, static_cast<int32_t>(object->id));
804-
ctx.set_array_value(table, 3, object);
804+
ctx.set_array_value(table, 3, static_cast<void*>(object));
805805

806806
lua_pushlightuserdata(vm, &game_object_meta_table_key); // class object k
807807
lua_gettable(vm, LUA_REGISTRYINDEX); // class object mt

LuaSTG/LuaSTG/LuaSTG.manifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
3-
<assemblyIdentity type="win32" name="ChuiKingShek.LuaSTG.Sub" version="0.21.107.0"/>
3+
<assemblyIdentity type="win32" name="ChuiKingShek.LuaSTG.Sub" version="0.21.108.0"/>
44
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
55
<security>
66
<requestedPrivileges>

engine/lua/lua/plus.hpp

Lines changed: 82 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ namespace lua {
5858

5959
template<size_t N>
6060
void push_value(char const (&str)[N]) const {
61-
for (size_t len = N - 1; len > 0; len -= 1) {
62-
if (str[len] != '\0') {
63-
lua_pushlstring(L, str, len + 1);
61+
for (auto i = static_cast<intptr_t>(N - 1); i >= 0; i -= 1) {
62+
if (str[i] != '\0') {
63+
lua_pushlstring(L, str, i + 1);
64+
return;
6465
}
6566
}
6667
lua_pushlstring(L, str, 0);
@@ -71,12 +72,24 @@ namespace lua {
7172
if constexpr (std::is_same_v<T, std::nullopt_t>) {
7273
lua_pushnil(L);
7374
}
75+
else if constexpr (std::is_enum_v<T>) {
76+
push_value(static_cast<std::underlying_type_t<T>>(value));
77+
}
7478
else if constexpr (std::is_same_v<T, bool>) {
7579
lua_pushboolean(L, value);
7680
}
81+
else if constexpr (std::is_same_v<T, int8_t>) {
82+
lua_pushinteger(L, value);
83+
}
7784
else if constexpr (std::is_same_v<T, uint8_t>) {
7885
lua_pushinteger(L, value);
7986
}
87+
else if constexpr (std::is_same_v<T, int16_t>) {
88+
lua_pushinteger(L, value);
89+
}
90+
else if constexpr (std::is_same_v<T, uint16_t>) {
91+
lua_pushinteger(L, value);
92+
}
8093
else if constexpr (std::is_same_v<T, int32_t>) {
8194
lua_pushinteger(L, value);
8295
}
@@ -89,6 +102,14 @@ namespace lua {
89102
lua_pushinteger(L, static_cast<int32_t>(value));
90103
}
91104
}
105+
else if constexpr (std::is_same_v<T, int64_t>) {
106+
// WARN: not full supported
107+
lua_pushnumber(L, static_cast<double>(value));
108+
}
109+
else if constexpr (std::is_same_v<T, uint64_t>) {
110+
// WARN: not full supported
111+
lua_pushnumber(L, static_cast<double>(value));
112+
}
92113
else if constexpr (std::is_same_v<T, float>) {
93114
lua_pushnumber(L, value);
94115
}
@@ -148,68 +169,36 @@ namespace lua {
148169
template<>
149170
inline void set_array_value(stack_index_t index, std::string_view value) { lua_pushlstring(L, value.data(), value.size()); lua_rawseti(L, -2, index.value); }
150171

151-
void set_array_value(stack_index_t const array_index, int32_t const index, std::nullopt_t) const { lua_pushnil(L); lua_rawseti(L, array_index.value, index); }
152-
void set_array_value(stack_index_t const array_index, int32_t const index, stack_index_t const value_index) const { lua_pushvalue(L, value_index.value); lua_rawseti(L, array_index.value, index); }
153-
void set_array_value(stack_index_t const array_index, int32_t const index, bool const value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
154-
void set_array_value(stack_index_t const array_index, int32_t const index, int32_t const& value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
155-
void set_array_value(stack_index_t const array_index, int32_t const index, std::string_view const& value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
156-
void set_array_value(stack_index_t const array_index, int32_t const index, void* ptr) const { lua_pushlightuserdata(L, ptr); lua_rawseti(L, array_index.value, index); }
157-
158-
inline size_t get_array_size(stack_index_t const index) const { return lua_objlen(L, index.value); }
159-
160-
inline void push_array_value_zero_base(stack_index_t array_index, size_t c_index) { lua_rawgeti(L, array_index.value, static_cast<int>(c_index + 1)); }
161-
162-
// C -> lua map
163-
164-
inline stack_index_t create_map(size_t reserve = 0u) { lua_createtable(L, 0, static_cast<int>(reserve)); return index_of_top(); }
172+
//void set_array_value(stack_index_t const array_index, int32_t const index, std::nullopt_t) const { lua_pushnil(L); lua_rawseti(L, array_index.value, index); }
173+
//void set_array_value(stack_index_t const array_index, int32_t const index, stack_index_t const value_index) const { lua_pushvalue(L, value_index.value); lua_rawseti(L, array_index.value, index); }
174+
//void set_array_value(stack_index_t const array_index, int32_t const index, bool const value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
175+
//void set_array_value(stack_index_t const array_index, int32_t const index, int32_t const value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
176+
//void set_array_value(stack_index_t const array_index, int32_t const index, std::string_view const& value) const { push_value(value); lua_rawseti(L, array_index.value, index); }
177+
//void set_array_value(stack_index_t const array_index, int32_t const index, void* ptr) const { lua_pushlightuserdata(L, ptr); lua_rawseti(L, array_index.value, index); }
178+
//void set_array_value(stack_index_t const array_index, int32_t const index, float const value) const { lua_pushnumber(L, value); lua_rawseti(L, array_index.value, index); }
165179

166180
template<typename T>
167-
inline void set_map_value(stack_index_t index, std::string_view key, T value) const { typename T::__invalid_type__ _{}; }
168-
169-
template<>
170-
inline void set_map_value(stack_index_t index, std::string_view key, int32_t value) const {
171-
push_value(key);
181+
void set_array_value(stack_index_t const array_index, stack_index_t const index, T const& value) const {
182+
lua_pushinteger(L, index.value);
172183
push_value(value);
173-
lua_settable(L, index.value);
184+
lua_settable(L, array_index.value);
174185
}
175-
176-
template<>
177-
inline void set_map_value(stack_index_t index, std::string_view key, uint32_t value) const {
178-
push_value(key);
179-
push_value(value);
180-
lua_settable(L, index.value);
186+
void set_array_value(stack_index_t const array_index, stack_index_t const index, void* const ptr) const {
187+
lua_pushinteger(L, index.value);
188+
lua_pushlightuserdata(L, ptr);
189+
lua_settable(L, array_index.value);
181190
}
182191

183-
template<>
184-
inline void set_map_value(stack_index_t index, std::string_view key, float value) const {
185-
push_value(key);
186-
push_value(value);
187-
lua_settable(L, index.value);
188-
}
192+
inline size_t get_array_size(stack_index_t const index) const { return lua_objlen(L, index.value); }
189193

190-
template<>
191-
inline void set_map_value(stack_index_t index, std::string_view key, double value) const {
192-
push_value(key);
193-
push_value(value);
194-
lua_settable(L, index.value);
195-
}
194+
inline void push_array_value_zero_base(stack_index_t array_index, size_t c_index) { lua_rawgeti(L, array_index.value, static_cast<int>(c_index + 1)); }
196195

197-
template<>
198-
inline void set_map_value(stack_index_t index, std::string_view key, std::string_view value) const {
199-
push_value(key);
200-
push_value(value);
201-
lua_settable(L, index.value);
202-
}
196+
// C -> lua map
203197

204-
template<>
205-
inline void set_map_value(stack_index_t index, std::string_view key, stack_index_t value) const {
206-
push_value(key);
207-
push_value(value);
208-
lua_settable(L, index.value);
209-
}
198+
inline stack_index_t create_map(size_t reserve = 0u) const { lua_createtable(L, 0, static_cast<int>(reserve)); return index_of_top(); }
210199

211-
template<>
212-
inline void set_map_value(stack_index_t index, std::string_view key, lua_CFunction value) const {
200+
template<typename T>
201+
inline void set_map_value(stack_index_t const index, std::string_view const key, T const value) const {
213202
push_value(key);
214203
push_value(value);
215204
lua_settable(L, index.value);
@@ -244,15 +233,38 @@ namespace lua {
244233

245234
template<typename T>
246235
[[nodiscard]] T get_value(stack_index_t const index) const {
247-
if constexpr (std::is_same_v<T, bool>) {
236+
if constexpr (std::is_enum_v<T>) {
237+
return static_cast<T>(get_value<std::underlying_type_t<T>>(index));
238+
}
239+
else if constexpr (std::is_same_v<T, bool>) {
248240
return lua_toboolean(L, index.value);
249241
}
242+
else if constexpr (std::is_same_v<T, int8_t>) {
243+
return static_cast<int8_t>(luaL_checkinteger(L, index.value));
244+
}
245+
else if constexpr (std::is_same_v<T, uint8_t>) {
246+
return static_cast<uint8_t>(luaL_checkinteger(L, index.value));
247+
}
248+
else if constexpr (std::is_same_v<T, int16_t>) {
249+
return static_cast<int16_t>(luaL_checkinteger(L, index.value));
250+
}
251+
else if constexpr (std::is_same_v<T, uint16_t>) {
252+
return static_cast<uint16_t>(luaL_checkinteger(L, index.value));
253+
}
250254
else if constexpr (std::is_same_v<T, int32_t>) {
251255
return static_cast<int32_t>(luaL_checkinteger(L, index.value));
252256
}
253257
else if constexpr (std::is_same_v<T, uint32_t>) {
254258
return static_cast<uint32_t>(luaL_checknumber(L, index.value));
255259
}
260+
else if constexpr (std::is_same_v<T, int64_t>) {
261+
// WARN: not full supported
262+
return static_cast<int64_t>(luaL_checknumber(L, index.value));
263+
}
264+
else if constexpr (std::is_same_v<T, uint64_t>) {
265+
// WARN: not full supported
266+
return static_cast<uint64_t>(luaL_checknumber(L, index.value));
267+
}
256268
else if constexpr (std::is_same_v<T, float>) {
257269
return static_cast<float>(luaL_checknumber(L, index.value));
258270
}
@@ -279,61 +291,26 @@ namespace lua {
279291

280292
template<typename T>
281293
[[nodiscard]] T get_value(stack_index_t const index, T const& default_value) const {
282-
if constexpr (std::is_same_v<T, bool>) {
283-
if (has_value(index))
284-
return lua_toboolean(L, index.value);
285-
return default_value;
286-
}
287-
else if constexpr (std::is_same_v<T, int32_t>) {
288-
return static_cast<int32_t>(luaL_optinteger(L, index.value, default_value));
289-
}
290-
else if constexpr (std::is_same_v<T, uint32_t>) {
291-
return static_cast<uint32_t>(luaL_optnumber(L, index.value, static_cast<lua_Number>(default_value)));
292-
}
293-
else if constexpr (std::is_same_v<T, float>) {
294-
if (has_value(index))
295-
return static_cast<float>(luaL_checknumber(L, index.value));
296-
return default_value;
297-
}
298-
else if constexpr (std::is_same_v<T, double>) {
299-
if (has_value(index))
300-
return luaL_checknumber(L, index.value);
301-
return default_value;
302-
}
303-
else {
304-
static_assert(false, "FIXME");
305-
return {};
306-
}
294+
if (!is_non_or_nil(index))
295+
return get_value<T>(index);
296+
return default_value;
307297
}
308298

309299
// array & map
310300

311301
template<typename T>
312-
inline T get_array_value(stack_index_t array_index, stack_index_t lua_index) const { typename T::__invalid_type__ _{}; }
313-
314-
template<>
315-
inline stack_index_t get_array_value(stack_index_t array_index, stack_index_t lua_index) const {
316-
lua_pushinteger(L, lua_index.value);
302+
inline T get_array_value(stack_index_t const array_index, stack_index_t const index) const {
303+
lua_pushinteger(L, index.value);
317304
lua_gettable(L, array_index.value);
318-
return { lua_gettop(L) };
319-
}
320-
321-
template<>
322-
inline int32_t get_array_value(stack_index_t array_index, stack_index_t lua_index) const {
323-
lua_pushinteger(L, lua_index.value);
324-
lua_gettable(L, array_index.value);
325-
auto const result = static_cast<int32_t>(luaL_checkinteger(L, -1));
326-
lua_pop(L, 1);
305+
auto const result = get_value<T>(-1);
306+
pop_value();
327307
return result;
328308
}
329-
330309
template<>
331-
inline uint32_t get_array_value(stack_index_t array_index, stack_index_t lua_index) const {
332-
lua_pushinteger(L, lua_index.value);
310+
inline stack_index_t get_array_value(stack_index_t const array_index, stack_index_t const index) const {
311+
lua_pushinteger(L, index.value);
333312
lua_gettable(L, array_index.value);
334-
auto const result = static_cast<uint32_t>(luaL_checknumber(L, -1));
335-
lua_pop(L, 1);
336-
return result;
313+
return { lua_gettop(L) };
337314
}
338315

339316
template<typename T>
@@ -382,9 +359,13 @@ namespace lua {
382359
template<typename T>
383360
T* as_userdata(stack_index_t const index) const { return static_cast<T*>(luaL_checkudata(L, index.value, T::class_name.data())); }
384361

362+
template<typename T>
363+
T* as_userdata(stack_index_t const index, std::string_view const class_name) const { return static_cast<T*>(luaL_checkudata(L, index.value, class_name.data())); }
364+
385365
// type
386366

387367
[[nodiscard]] bool has_value(stack_index_t const index) const { return lua_type(L, index.value) != LUA_TNONE; }
368+
[[nodiscard]] bool is_non_or_nil(stack_index_t const index) const { auto const type = lua_type(L, index.value); return type == LUA_TNONE || type == LUA_TNIL; }
388369
[[nodiscard]] bool is_nil(stack_index_t const index) const { return lua_type(L, index.value) == LUA_TNIL; }
389370
[[nodiscard]] bool is_boolean(stack_index_t const index) const { return lua_type(L, index.value) == LUA_TBOOLEAN; }
390371
[[nodiscard]] bool is_number(stack_index_t const index) const { return lua_type(L, index.value) == LUA_TNUMBER; }

0 commit comments

Comments
 (0)