diff --git a/samples/bin/library/scripts/emmy/utils/color.lua b/samples/bin/library/scripts/emmy/utils/color.lua new file mode 100644 index 00000000..a5e458c6 --- /dev/null +++ b/samples/bin/library/scripts/emmy/utils/color.lua @@ -0,0 +1,86 @@ +---@class color +local color = { + ---@type number + r = 1.0, + + ---@type number + g = 1.0, + + ---@type number + b = 1.0, + + ---@type number + a = 1.0 +} + +---@overload fun(): color +---@overload fun(c: color): color +---@overload fun(c: color32): color +---@overload fun(v: v4f): color +---@overload fun(v: v3f, a: number): color +---@overload fun(r: number, g: number, b: number, a: number): color +---@return color +function color.new() end + +---@return color +function color.clear() end + +---@return color +function color.black() end + +---@return color +function color.white() end + +---@return color +function color.red() end + +---@return color +function color.green() end + +---@return color +function color.blue() end + +---@return color +function color.yellow() end + +---@return color +function color.magenta() end + +---@return color +function color.cyan() end + +---@param l color +---@param r color +---@return boolean +function color.approximately(l, r) end + +---@param c color +---@return number +function color.minimum(c) end + +---@param c color +---@return number +function color.maximum(c) end + +---@param c color +---@param cmin color +---@return color +function color.minimized(c,cmin) end + +---@param c color +---@param cmax color +---@return color +function color.maximized(c,cmax) end + +---@param c color +---@param cmin color +---@param cmax color +---@return color +function color.clamped(c,cmin,cmax) end + +---@param c color +---@return boolean +function color.contains_nan(c) end + +---@type color +_G.color = _G.color or color diff --git a/samples/bin/library/scripts/emmy/utils/color32.lua b/samples/bin/library/scripts/emmy/utils/color32.lua new file mode 100644 index 00000000..4f151763 --- /dev/null +++ b/samples/bin/library/scripts/emmy/utils/color32.lua @@ -0,0 +1,86 @@ +---@class color32 +local color32 = { + ---@type number + r = 255, + + ---@type number + g = 255, + + ---@type number + b = 255, + + ---@type number + a = 255 +} + +---@overload fun(): color32 +---@overload fun(c: color): color32 +---@overload fun(c: color32): color32 +---@overload fun(v: v4f): color32 +---@overload fun(v: v3f, a: number): color32 +---@overload fun(r: number, g: number, b: number, a: number): color32 +---@return color32 +function color32.new() end + +---@return color32 +function color32.clear() end + +---@return color32 +function color32.black() end + +---@return color32 +function color32.white() end + +---@return color32 +function color32.red() end + +---@return color32 +function color32.green() end + +---@return color32 +function color32.blue() end + +---@return color32 +function color32.yellow() end + +---@return color32 +function color32.magenta() end + +---@return color32 +function color32.cyan() end + +---@param l color32 +---@param r color32 +---@return boolean +function color32.approximately(l, r) end + +---@param c color32 +---@return number +function color32.minimum(c) end + +---@param c color32 +---@return number +function color32.maximum(c) end + +---@param c color32 +---@param cmin color32 +---@return color32 +function color32.minimized(c,cmin) end + +---@param c color32 +---@param cmax color32 +---@return color32 +function color32.maximized(c,cmax) end + +---@param c color32 +---@param cmin color32 +---@param cmax color32 +---@return color32 +function color32.clamped(c,cmin,cmax) end + +---@param c color32 +---@return boolean +function color32.contains_nan(c) end + +---@type color32 +_G.color32 = _G.color32 or color32 diff --git a/samples/bin/library/scripts/emmy/utils/str_hash.lua b/samples/bin/library/scripts/emmy/utils/str_hash.lua new file mode 100644 index 00000000..06bd2d5e --- /dev/null +++ b/samples/bin/library/scripts/emmy/utils/str_hash.lua @@ -0,0 +1,20 @@ +---@class str_hash +local str_hash = { + ---@type boolean + empty = true, + + ---@type number + hash = 0 +} + +---@overload fun(): str_hash +---@overload fun(s: string): str_hash +---@return str_hash +function str_hash.new() end + +---@overload fun(s: str_hash) +---@param s str_hash +function str_hash.clear(s) end + +---@type str_hash +_G.str_hash = _G.str_hash or str_hash diff --git a/sources/enduro2d/high/bindings/utils_binds/color32_binds.cpp b/sources/enduro2d/high/bindings/utils_binds/color32_binds.cpp index 3c56c651..036de628 100644 --- a/sources/enduro2d/high/bindings/utils_binds/color32_binds.cpp +++ b/sources/enduro2d/high/bindings/utils_binds/color32_binds.cpp @@ -11,8 +11,7 @@ using namespace e2d; namespace e2d::bindings::utils { void bind_color32(sol::state& l) { - l["e2d"].get_or_create() - .new_usertype("color32", + l.new_usertype("color32", sol::constructors< color32(), color32(color), @@ -68,9 +67,6 @@ namespace e2d::bindings::utils "maximized", sol::resolve(&math::maximized), "clamped", sol::resolve(&math::clamped), - "contains_nan", sol::resolve(&math::contains_nan), - - "pack_color", sol::resolve(&colors::pack_color32), - "unpack_color", sol::resolve(&colors::unpack_color32)); + "contains_nan", sol::resolve(&math::contains_nan)); } } diff --git a/sources/enduro2d/high/bindings/utils_binds/color_binds.cpp b/sources/enduro2d/high/bindings/utils_binds/color_binds.cpp index b4e58b41..e6c3940b 100644 --- a/sources/enduro2d/high/bindings/utils_binds/color_binds.cpp +++ b/sources/enduro2d/high/bindings/utils_binds/color_binds.cpp @@ -11,8 +11,7 @@ using namespace e2d; namespace e2d::bindings::utils { void bind_color(sol::state& l) { - l["e2d"].get_or_create() - .new_usertype("color", + l.new_usertype("color", sol::constructors< color(), color(color), @@ -68,9 +67,6 @@ namespace e2d::bindings::utils "maximized", sol::resolve(&math::maximized), "clamped", sol::resolve(&math::clamped), - "contains_nan", sol::resolve(&math::contains_nan), - - "pack_color", sol::resolve(&colors::pack_color), - "unpack_color", sol::resolve(&colors::unpack_color)); + "contains_nan", sol::resolve(&math::contains_nan)); } } diff --git a/sources/enduro2d/high/bindings/utils_binds/str_hash_binds.cpp b/sources/enduro2d/high/bindings/utils_binds/str_hash_binds.cpp index 1914d46e..4c00d11c 100644 --- a/sources/enduro2d/high/bindings/utils_binds/str_hash_binds.cpp +++ b/sources/enduro2d/high/bindings/utils_binds/str_hash_binds.cpp @@ -11,12 +11,11 @@ using namespace e2d; namespace e2d::bindings::utils { void bind_str_hash(sol::state& l) { - l["e2d"].get_or_create() - .new_usertype("str_hash", + l.new_usertype("str_hash", sol::constructors< str_hash(), - str_hash(const char*), - str_hash(str_view)>(), + str_hash(const char*) + >(), sol::meta_function::equal_to, sol::resolve(::operator==), sol::meta_function::less_than, sol::resolve(::operator<), diff --git a/untests/sources/untests_high/luasol.cpp b/untests/sources/untests_high/luasol.cpp index cd115576..4fcd9a47 100644 --- a/untests/sources/untests_high/luasol.cpp +++ b/untests/sources/untests_high/luasol.cpp @@ -31,20 +31,20 @@ TEST_CASE("luasol") { SECTION("vec2/vec3/vec4") { v2f r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local v = e2d.v2f.new(1,2) - return e2d.v2f.new((v + v + 2).y) + local v = v2f.new(1,2) + return v2f.new((v + v + 2).y) )lua"); }); v3f r1 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local v = e2d.v3f.new(1,2,3) - return e2d.v3f.new((v + v + 2).y) + local v = v3f.new(1,2,3) + return v3f.new((v + v + 2).y) )lua"); }); v4f r2 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local v = e2d.v4f.new(1,2,3,4) - return e2d.v4f.new((v + v + 2).y) + local v = v4f.new(1,2,3,4) + return v4f.new((v + v + 2).y) )lua"); }); REQUIRE(r0 == v2f(6)); @@ -55,7 +55,7 @@ TEST_CASE("luasol") { SECTION("quat") { v3f r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - return e2d.v3f.new(1,2,3) * e2d.q4f.make_quat_from_axis_angle(e2d.radf.new(10), e2d.v3f.new(1,2,3)) + return v3f.new(1,2,3) * q4f.make_from_axis_angle(radf.new(10), v3f.new(1,2,3)) )lua"); }); REQUIRE(r0 == v3f(1,2,3) * math::make_quat_from_axis_angle(radf(10.f), v3f(1,2,3))); @@ -64,23 +64,23 @@ TEST_CASE("luasol") { SECTION("mat2/mat2/mat3") { std::pair r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local m = e2d.m2f.make_scale_matrix2(2,3) - local rm, s = e2d.m2f.inversed(m) - return rm * e2d.m2f.identity(), s + local m = m2f.make_scale(2,3) + local rm, s = m2f.inversed(m) + return rm * m2f.identity(), s )lua"); }); std::pair r1 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local m = e2d.m3f.make_rotation_matrix3(e2d.degf.new(45),2,3,4) - local rm, s = e2d.m3f.inversed(m) - return rm * e2d.m3f.identity(), s + local m = m3f.make_rotation(degf.new(45),2,3,4) + local rm, s = m3f.inversed(m) + return rm * m3f.identity(), s )lua"); }); std::pair r2 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local m = e2d.m4f.make_translation_matrix4(2,3,4) - local rm, s = e2d.m4f.inversed(m) - return rm * e2d.m4f.identity(), s + local m = m4f.make_translation(2,3,4) + local rm, s = m4f.inversed(m) + return rm * m4f.identity(), s )lua"); }); REQUIRE(r0.second); @@ -94,15 +94,15 @@ TEST_CASE("luasol") { SECTION("rect/aabb") { bool r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local b = e2d.b2f.unit() * 2 - return b:inside(e2d.v2f.new(1.5,1.5)) + local b = b2f.unit() * 2 + return b:inside(v2f.new(1.5,1.5)) )lua"); }); REQUIRE(r0); bool r1 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local b = e2d.b3f.unit() * 2 - return b:overlaps(e2d.b3f.new(1.5,1.5,1.5,2,2,2)) + local b = b3f.unit() * 2 + return b:overlaps(b3f.new(1.5,1.5,1.5,2,2,2)) )lua"); }); REQUIRE(r1); @@ -111,14 +111,14 @@ TEST_CASE("luasol") { SECTION("trs2/trs3") { radf r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local t = e2d.t2f.make_rotation_trs2(e2d.degf.new(45)) + local t = t2f.make_rotation(degf.new(45)) return t.rotation )lua"); }); REQUIRE(r0 == math::to_rad(degf(45.f))); v3f r1 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - local t = e2d.t3f.make_translation_trs3(e2d.v3f.new(1,2,3)) + local t = t3f.make_translation(v3f.new(1,2,3)) return t.translation )lua"); }); @@ -128,15 +128,33 @@ TEST_CASE("luasol") { SECTION("color/color32") { color r0 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - return e2d.color.white() * 0.5 + return color.white() * 0.5 )lua"); }); REQUIRE(r0 == color(0.5f,0.5f,0.5f,0.5f)); color32 r1 = l.with_state([](sol::state& lua){ return lua.script(R"lua( - return e2d.color32.white() - 1 + return color32.white() - 1 )lua"); }); REQUIRE(r1 == color32(254,254,254,254)); } + + SECTION("str_hash") { + str_hash r0 = l.with_state([](sol::state& lua){ + return lua.script(R"lua( + local s = str_hash.new("hello") + s:clear() + return s + )lua"); + }); + REQUIRE(r0.empty()); + u32 r1 = l.with_state([](sol::state& lua){ + return lua.script(R"lua( + local s = str_hash.new("hello") + return s.hash + )lua"); + }); + REQUIRE(r1 == str_hash("hello").hash()); + } }