Skip to content

Commit

Permalink
ubx.lua: port_read/write: improve arg checking
Browse files Browse the repository at this point in the history
  • Loading branch information
kmarkus committed Jan 30, 2020
1 parent dfee3e5 commit 458233d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lua/ubx.lua.source
Original file line number Diff line number Diff line change
Expand Up @@ -1103,15 +1103,17 @@ end
--- Read from a port.
--
function M.port_read(p, rval)
if type(rval)~='cdata' then
if not M.is_data(rval) then
rval=M.port_alloc_read_sample(p)
end
return ubx.__port_read(p, rval), rval
end

function M.port_write(p, wval)
if type(wval) == 'cdata' then
if M.is_data(wval) then
ubx.__port_write(p, wval)
elseif type(wval) == 'cdata' then
error("port_write: invalid cdata. expected ubx_data, got "..ffi.typeof(wval))
else
local sample = M.port_alloc_write_sample(p)
sample:set(wval)
Expand Down

0 comments on commit 458233d

Please sign in to comment.