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;
|
||||
|
||||
fn view_id_err(L: *zlua.Lua) noreturn {
|
||||
L.raiseErrorStr("The view id must be >= 0 and < inf", .{});
|
||||
}
|
||||
|
||||
// ---@alias view_id integer
|
||||
|
||||
// ---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
|
||||
// ---@param view_id view_id 0 maps to focused view
|
||||
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);
|
||||
if(view) |v| {
|
||||
|
|
@ -67,9 +71,9 @@ pub fn close(L: *zlua.Lua) i32 {
|
|||
pub fn set_position(L: *zlua.Lua) i32 {
|
||||
std.log.debug("repositioning", .{});
|
||||
|
||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
||||
const x: i32 = @intFromFloat(@round(L.checkNumber(2)));
|
||||
const y: i32 = @intFromFloat(@round(L.checkNumber(3)));
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
const x = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The x must be > -inf and < inf", .{});
|
||||
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});
|
||||
|
||||
|
|
@ -87,13 +91,17 @@ pub fn set_position(L: *zlua.Lua) i32 {
|
|||
// ---@param width number width for view
|
||||
// ---@param height number height for view
|
||||
pub fn set_size(L: *zlua.Lua) i32 {
|
||||
const view_id: u64 = @intCast(L.checkInteger(1));
|
||||
const width = LuaUtils.coerceNumber(i32, L.checkNumber(2)) catch L.raiseErrorStr("The width must be >= 0 and < inf", .{});
|
||||
const height = LuaUtils.coerceNumber(i32, L.checkNumber(3)) catch L.raiseErrorStr("The height must be >= 0 and < inf", .{});
|
||||
const view_id = LuaUtils.coerceInteger(u64, L.checkInteger(1)) catch view_id_err(L);
|
||||
// We use u32s here to enforce a minimum size of zero. The call to resize a
|
||||
// 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);
|
||||
if(view) |v| {
|
||||
v.setSize(width, height);
|
||||
v.setSize(@intCast(width), @intCast(height));
|
||||
}
|
||||
|
||||
L.pushNil();
|
||||
|
|
@ -101,7 +109,7 @@ pub fn set_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);
|
||||
if (view) |v| {
|
||||
L.newTable();
|
||||
|
|
@ -154,7 +162,7 @@ pub fn set_focused(L: *zlua.Lua) i32 {
|
|||
// ---@param view_id view_id 0 maps to focused view
|
||||
// ---@return string?
|
||||
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);
|
||||
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
|
||||
// ---@return string?
|
||||
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);
|
||||
if(view) |v| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue