@@ -28,21 +28,27 @@ if proj_path == nil then
28
28
error (" Failed to find internal library" )
29
29
end
30
30
local lib = ffi .load (proj_path )
31
- -- local ctx = lib.pj_ctx_alloc()
32
- -- if ctx == nil then
33
- -- error('Failed to create proj4 context')
34
- -- end
35
- -- ffi.gc(ctx, lib.pj_ctx_free)
31
+ local ctx = lib .pj_ctx_alloc ()
32
+ if ctx == nil then
33
+ error (' Failed to create proj4 context' )
34
+ end
35
+ ffi .gc (ctx , lib .pj_ctx_free )
36
36
37
37
local projections = {}
38
38
39
39
local PROJ_VERSION = ffi .string (lib .libproj_version ())
40
40
projections .PROJ_VERSION = PROJ_VERSION
41
41
42
+ local function ctx_raise_errno (errno )
43
+ assert (errno ~= 0 )
44
+ local errstr = lib .pj_strerrno (errno )
45
+ local errstr = errstr ~= nil and ffi .string (errstr ) or " Unknown error"
46
+ error (' PROJ: ' .. errstr )
47
+ end
48
+
42
49
local function ctx_raise ()
43
- -- local errno = lib.pj_ctx_get_errno(ctx)
44
- local errno = lib .pj_get_errno (ctx )
45
- error (' PROJ: ' .. ffi .string (lib .pj_strerrno (errno )))
50
+ local errno = lib .pj_ctx_get_errno (ctx )
51
+ return ctx_raise_errno (errno )
46
52
end
47
53
48
54
local proj_t = ffi .typeof (' struct PJ' )
@@ -105,9 +111,9 @@ local function proj_transformv(src, dst, count, xvec, yvec, zvec)
105
111
" xvec: double[], yvec: double[], zvec: double[])" )
106
112
end
107
113
proj_arg (src )
108
- local rc = lib .pj_transform (src , dst , count , 1 , xvec , yvec , zvec )
109
- if rc ~= 0 then
110
- ctx_raise ( )
114
+ local errno = lib .pj_transform (src , dst , count , 1 , xvec , yvec , zvec )
115
+ if errno ~= 0 then
116
+ ctx_raise_errno ( errno )
111
117
end
112
118
return true
113
119
end
0 commit comments