You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
567 B
Lua

local ffi = require("ffi")
local error = error
local ffi_c, ffi_errno, ffi_string = ffi.C, ffi.errno, ffi.string
ffi.cdef("char* strerror(int num);")
local module = {}
local function errno_error(name, errno, level)
errno = errno or ffi_errno()
local str = ffi_c.strerror(errno)
if not level then level = 1 end
error(name..": "..errno..": "..ffi_string(str), level+1)
end
module.error = errno_error
function module.assert(name, expr, level)
if not expr then
if not level then level = 1 end
errno_error(name, nil, level+1)
end
end
return module