Use assert for type checking

This commit is contained in:
2025-06-19 21:38:34 +10:00
parent 1c821d8804
commit 1ebeaa9e95
4 changed files with 23 additions and 31 deletions

View File

@@ -434,7 +434,7 @@ impl<'r, 'm> MetatypeMethodBuilder<'r, 'm> {
write!(self.prelude, "local __{name}_len = 0; ").unwrap();
write!(
self.prelude,
r#"if {name} ~= nil then assert(type({name}) == "string", "expected string in argument '{name}', got " .. type({name})); __{name}_len = #{name}; end; "#
r#"if {name} ~= nil then assert(type({name}) == "string", "string expected in argument '{name}', got " .. type({name})); __{name}_len = #{name}; end; "#
)
.unwrap();
self
@@ -520,7 +520,7 @@ macro_rules! impl_copy_primitive {
type FromValue = $rtype;
fn prelude(arg: &str) -> impl Display {
display!(r#"assert(type({arg}) == "{0}", "expected {0} in argument '{arg}', got " .. type({arg})); "#, $ltype)
display!(r#"assert(type({arg}) == "{0}", "{0} expected in argument '{arg}', got " .. type({arg})); "#, $ltype)
}
fn convert(from: Self::From) -> Self {

View File

@@ -24,7 +24,7 @@ unsafe impl FromFfi for *const [u8] {
let ct = lua_buf::name();
write!(
f,
r#"if {arg} ~= nil then assert(type({arg}) == "string", "expected string in argument '{arg}', got " .. type({arg})); "#
r#"if {arg} ~= nil then assert(type({arg}) == "string", "string expected in argument '{arg}', got " .. type({arg})); "#
)?;
write!(f, "{arg} = {ct}({arg}, #{arg}); end; ")
})
@@ -55,7 +55,7 @@ unsafe impl FromFfi for &str {
let ct = lua_buf::name();
write!(
f,
r#"assert(type({arg}) == "string", "expected string in argument '{arg}', got " .. type({arg})); "#
r#"assert(type({arg}) == "string", "string expected in argument '{arg}', got " .. type({arg})); "#
)?;
write!(
f,