* dl_shell 批量缩放
This commit is contained in:
@@ -6,86 +6,7 @@
|
||||
#include "script/dl_lua.h"
|
||||
#include "ui/dl_ui_manager.h"
|
||||
#include "render/dl_image.h"
|
||||
|
||||
#include <LuaBridge/Array.h>
|
||||
#include <LuaBridge/Vector.h>
|
||||
|
||||
|
||||
// Array 绑定
|
||||
namespace luabridge {
|
||||
|
||||
//=================================================================================================
|
||||
/**
|
||||
* @brief Stack specialization for `dl::Array`.
|
||||
*/
|
||||
template <class T, std::size_t Size>
|
||||
struct Stack<dl::Array<T, Size>>
|
||||
{
|
||||
using Type = dl::Array<T, Size>;
|
||||
|
||||
[[nodiscard]] static Result push(lua_State* L, const Type& array)
|
||||
{
|
||||
#if LUABRIDGE_SAFE_STACK_CHECKS
|
||||
if (!lua_checkstack(L, 3))
|
||||
return makeErrorCode(ErrorCode::LuaStackOverflow);
|
||||
#endif
|
||||
|
||||
StackRestore stackRestore(L);
|
||||
|
||||
lua_createtable(L, static_cast<int>(Size), 0);
|
||||
|
||||
for (std::size_t i = 0; i < Size; ++i)
|
||||
{
|
||||
lua_pushinteger(L, static_cast<lua_Integer>(i + 1));
|
||||
|
||||
auto result = Stack<T>::push(L, array[i]);
|
||||
if (!result)
|
||||
return result;
|
||||
|
||||
lua_settable(L, -3);
|
||||
}
|
||||
|
||||
stackRestore.reset();
|
||||
return {};
|
||||
}
|
||||
|
||||
[[nodiscard]] static TypeResult<Type> get(lua_State* L, int index)
|
||||
{
|
||||
if (!lua_istable(L, index))
|
||||
return makeErrorCode(ErrorCode::InvalidTypeCast);
|
||||
|
||||
if (get_length(L, index) != Size)
|
||||
return makeErrorCode(ErrorCode::InvalidTableSizeInCast);
|
||||
|
||||
const StackRestore stackRestore(L);
|
||||
|
||||
Type array;
|
||||
|
||||
int absIndex = lua_absindex(L, index);
|
||||
lua_pushnil(L);
|
||||
|
||||
int arrayIndex = 0;
|
||||
while (lua_next(L, absIndex) != 0)
|
||||
{
|
||||
auto item = Stack<T>::get(L, -1);
|
||||
if (!item)
|
||||
return makeErrorCode(ErrorCode::InvalidTypeCast);
|
||||
|
||||
array[arrayIndex++] = *item;
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
[[nodiscard]] static bool isInstance(lua_State* L, int index)
|
||||
{
|
||||
return lua_istable(L, index) && get_length(L, index) == Size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace luabridge
|
||||
|
||||
#include "script/dl_lua_register_container.h"
|
||||
|
||||
// 枚举类绑定
|
||||
|
||||
@@ -109,26 +30,36 @@ namespace dl
|
||||
delete img;
|
||||
}
|
||||
|
||||
std::string lua_to_string(const Position2& pos)
|
||||
{
|
||||
return to_string(pos);
|
||||
}
|
||||
|
||||
void lua_register_base(lua_State* L)
|
||||
{
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.addFunction("log", lua_log);
|
||||
.addFunction("log", lua_log)
|
||||
.addFunction("delete", lua_delete)
|
||||
.addFunction("to_string",
|
||||
luabridge::overload<const Position2&>(lua_to_string));
|
||||
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.addFunction("delete", lua_delete);
|
||||
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.beginNamespace("String")
|
||||
.addFunction("ErasePath", String::ErasePath)
|
||||
.addFunction("GetFileStem", String::GetFileStem)
|
||||
.addFunction("toPosition2", String::toPosition2)
|
||||
.addFunction("ReplaceExtension",
|
||||
luabridge::overload<std::string_view, std::string_view>(String::ReplaceExtension))
|
||||
.addFunction("EraseFilename",
|
||||
luabridge::overload<std::string_view>(String::EraseFilename))
|
||||
.endNamespace();
|
||||
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.beginNamespace("Img")
|
||||
.addVariable("REGEX_FORMAT", Img::REGEX_FORMAT)
|
||||
.addFunction("ResizeImage",
|
||||
luabridge::overload<const Image*,float>(Img::ResizeImage),
|
||||
luabridge::overload<const Image*, float>(Img::ResizeImage),
|
||||
luabridge::overload<const Image*, const Size&>(Img::ResizeImage))
|
||||
.endNamespace();
|
||||
|
||||
@@ -138,8 +69,8 @@ namespace dl
|
||||
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.addFunction("createImage",
|
||||
luabridge::overload<std::string_view>(&createImage),
|
||||
luabridge::overload<const Size&, const Color&>(&createImage))
|
||||
luabridge::overload<std::string_view>(createImage),
|
||||
luabridge::overload<const Size&, const Color&>(createImage))
|
||||
.addFunction("saveImage", &saveImage);
|
||||
}
|
||||
|
||||
@@ -177,14 +108,17 @@ namespace dl
|
||||
|
||||
luabridge::getGlobalNamespace(L)
|
||||
.beginNamespace("g_file")
|
||||
.addFunction("GetPathFileAll", &lua_GetPathFileAll_3, &lua_GetPathFileAll_2, &lua_GetPathFileAll_1)
|
||||
.addFunction("GetAbsolute", &File::GetAbsolute)
|
||||
.addFunction("GetRelative", &File::GetRelative)
|
||||
.addFunction("CreateFolder", &File::CreateFolder)
|
||||
.addFunction("Rename", &File::Rename)
|
||||
.addFunction("Copy", &File::Copy)
|
||||
.addFunction("GetFilePath", &File::GetFilePath)
|
||||
.addFunction("GetFileName", &File::GetFileName)
|
||||
.addFunction("GetPathFileAll", lua_GetPathFileAll_3, lua_GetPathFileAll_2, lua_GetPathFileAll_1)
|
||||
.addFunction("GetAbsolute", File::GetAbsolute)
|
||||
.addFunction("GetRelative", File::GetRelative)
|
||||
.addFunction("CreateFolder", File::CreateFolder)
|
||||
.addFunction("Rename", File::Rename)
|
||||
.addFunction("Copy", File::Copy)
|
||||
.addFunction("GetFilePath", File::GetFilePath)
|
||||
.addFunction("GetFileName", File::GetFileName)
|
||||
.addFunction("GetString", File::GetString)
|
||||
.addFunction("SaveString",
|
||||
luabridge::overload<std::string_view, std::string_view>(File::SaveString))
|
||||
.endNamespace();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user