Use assert for type checking
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user