mirror of
https://github.com/MezzalunaWM/Mezzaluna.git
synced 2026-03-07 19:49:53 -05:00
more safety in lua stuff
This commit is contained in:
parent
54c1a976c8
commit
bfdc8b8c9d
1 changed files with 19 additions and 11 deletions
|
|
@ -6,6 +6,10 @@ const LuaUtils = @import("LuaUtils.zig");
|
||||||
|
|
||||||
const server = &@import("../main.zig").server;
|
const server = &@import("../main.zig").server;
|
||||||
|
|
||||||
|
fn view_id_err(L: *zlua.Lua) noreturn {
|
||||||
|
L.raiseErrorStr("The view id must be >= 0 and < inf", .{});
|
||||||
|
}
|
||||||
|
|
||||||
// ---@alias view_id integer
|
// ---@alias view_id integer
|
||||||
|
|
||||||
// ---Get the ids for all available views
|
// ---Get the ids for all available views
|
||||||
|
|
@ -49,7 +53,7 @@ pub fn get_focused_id(L: *zlua.Lua) i32 {
|
||||||
// ---Close the view with view_id
|
// ---Close the view with view_id
|
||||||
// ---@param view_id view_id 0 maps to focused view
|
// ---@param view_id view_id 0 maps to focused view
|
||||||
pub fn close(L: *zlua.Lua) i32 {
|
pub fn close(L: *zlua.Lua) i32 {
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
|
|
||||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||||
if(view) |v| {
|
if(view) |v| {
|
||||||
|
|
@ -67,9 +71,9 @@ pub fn close(L: *zlua.Lua) i32 {
|
||||||
pub fn set_position(L: *zlua.Lua) i32 {
|
pub fn set_position(L: *zlua.Lua) i32 {
|
||||||
std.log.debug("repositioning", .{});
|
std.log.debug("repositioning", .{});
|
||||||
|
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
const x: i32 = @intFromFloat(@round(L.checkNumber(2)));
|
const x = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The x must be > -inf and < inf", .{});
|
||||||
const y: i32 = @intFromFloat(@round(L.checkNumber(3)));
|
const y = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The y must be > -inf and < inf", .{});
|
||||||
|
|
||||||
std.log.debug("position to set: ({d}, {d})", .{x, y});
|
std.log.debug("position to set: ({d}, {d})", .{x, y});
|
||||||
|
|
||||||
|
|
@ -87,13 +91,17 @@ pub fn set_position(L: *zlua.Lua) i32 {
|
||||||
// ---@param width number width for view
|
// ---@param width number width for view
|
||||||
// ---@param height number height for view
|
// ---@param height number height for view
|
||||||
pub fn set_size(L: *zlua.Lua) i32 {
|
pub fn set_size(L: *zlua.Lua) i32 {
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
const width = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{});
|
// We use u32s here to enforce a minimum size of zero. The call to resize a
|
||||||
const height = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{});
|
// toplevel requires a i32, which doesn't make too much sense as there's an
|
||||||
|
// assertion in the code enforcing that both the width and height are greater
|
||||||
|
// than or equal to zero.
|
||||||
|
const width = LuaUtils.coerceNumber(u32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{});
|
||||||
|
const height = LuaUtils.coerceNumber(u32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{});
|
||||||
|
|
||||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||||
if(view) |v| {
|
if(view) |v| {
|
||||||
v.setSize(width, height);
|
v.setSize(@intCast(width), @intCast(height));
|
||||||
}
|
}
|
||||||
|
|
||||||
L.pushNil();
|
L.pushNil();
|
||||||
|
|
@ -101,7 +109,7 @@ pub fn set_size(L: *zlua.Lua) i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_size(L: *zlua.Lua) i32 {
|
pub fn get_size(L: *zlua.Lua) i32 {
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||||
if (view) |v| {
|
if (view) |v| {
|
||||||
L.newTable();
|
L.newTable();
|
||||||
|
|
@ -154,7 +162,7 @@ pub fn set_focused(L: *zlua.Lua) i32 {
|
||||||
// ---@param view_id view_id 0 maps to focused view
|
// ---@param view_id view_id 0 maps to focused view
|
||||||
// ---@return string?
|
// ---@return string?
|
||||||
pub fn get_title(L: *zlua.Lua) i32 {
|
pub fn get_title(L: *zlua.Lua) i32 {
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id: u64 = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
|
|
||||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||||
if(view) |v| {
|
if(view) |v| {
|
||||||
|
|
@ -175,7 +183,7 @@ pub fn get_title(L: *zlua.Lua) i32 {
|
||||||
// ---@param view_id view_id 0 maps to focused view
|
// ---@param view_id view_id 0 maps to focused view
|
||||||
// ---@return string?
|
// ---@return string?
|
||||||
pub fn get_app_id(L: *zlua.Lua) i32 {
|
pub fn get_app_id(L: *zlua.Lua) i32 {
|
||||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||||
|
|
||||||
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
const view: ?*View = if (view_id == 0) server.seat.focused_view else server.root.viewById(view_id);
|
||||||
if(view) |v| {
|
if(view) |v| {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue