• 73.33% Rate
  • 11 Hits
  • 4 Missed
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 1x
  • 1x
  • 1x
  • 1x
  • 1x
  • 1x
  • 88x
  • 9x
  • 1x
  • 1x
  • 1x
  • -------------------------------------------------------------------------------
  • -- Wrap calls to PUMAS C library in order to forward error messages
  • -- Author: Valentin Niess
  • -- License: GNU LGPL-3.0
  • -------------------------------------------------------------------------------
  • local ffi = require('ffi')
  • local clib = require('pumas.clib')
  • local error = require('pumas.error')
  • -------------------------------------------------------------------------------
  • -- Initialise the C error handler
  • -------------------------------------------------------------------------------
  • clib.pumas_error_initialise()
  • -------------------------------------------------------------------------------
  • -- Pattern for decoding PUMAS C library error messages
  • -------------------------------------------------------------------------------
  • local pattern = '[^}]+} (.*)$'
  • -------------------------------------------------------------------------------
  • -- Call a PUMAS C library function and forward any error message
  • -------------------------------------------------------------------------------
  • local raise_error = error.ErrorFunction{header = 'C library error'}
  • local function ccall (_, func,...)
  • if func(...) ~= 0 then
  • local msg = ffi.string(clib.pumas_error_get())
  • raise_error(msg:match(pattern))
  • end
  • end
  • -------------------------------------------------------------------------------
  • -- Protected call to a PUMAS C library function
  • -------------------------------------------------------------------------------
  • local function pccall (func,...)
  • if func(...) ~= 0 then
  • local msg = ffi.string(clib.pumas_error_get())
  • return msg:match(pattern)
  • end
  • end
  • -------------------------------------------------------------------------------
  • -- Return the package
  • -------------------------------------------------------------------------------
  • return setmetatable(
  • {protected = pccall},
  • {__call = ccall})