diff options
author | Mike Pall <mike> | 2011-05-08 22:34:40 +0200 |
---|---|---|
committer | Mike Pall <mike> | 2011-05-08 22:34:40 +0200 |
commit | 868ecad32ba7fb3eb763642e22ebb06938fdb359 (patch) | |
tree | 3d5651f9d73145fb3a2a8a8c6ab125feae359ba1 | |
parent | 77ba7726e2f8b6ffe86be6c89b5beda5cab86d2d (diff) | |
download | luajit-868ecad32ba7fb3eb763642e22ebb06938fdb359.tar.gz luajit-868ecad32ba7fb3eb763642e22ebb06938fdb359.tar.bz2 luajit-868ecad32ba7fb3eb763642e22ebb06938fdb359.zip |
FFI: Add ffi.errno().
-rw-r--r-- | doc/ext_ffi_api.html | 22 | ||||
-rw-r--r-- | src/lib_ffi.c | 8 |
2 files changed, 30 insertions, 0 deletions
diff --git a/doc/ext_ffi_api.html b/doc/ext_ffi_api.html index b1b42878..2d69cb49 100644 --- a/doc/ext_ffi_api.html +++ b/doc/ext_ffi_api.html | |||
@@ -336,6 +336,28 @@ objects. | |||
336 | 336 | ||
337 | <h2 id="util">Utility Functions</h2> | 337 | <h2 id="util">Utility Functions</h2> |
338 | 338 | ||
339 | <h3 id="ffi_errno"><tt>err = ffi.errno()</tt></h3> | ||
340 | <p> | ||
341 | Returns the error number set by the last C function call which | ||
342 | indicated an error condition. | ||
343 | </p> | ||
344 | <p> | ||
345 | This function offers a portable and OS-independent way to get the error | ||
346 | number. Note that only <em>some</em> C functions set the error | ||
347 | number. And it's only significant if the function actually indicated an | ||
348 | error condition (e.g. with a return value of <tt>-1</tt> or | ||
349 | <tt>NULL</tt>). Otherwise, it may or may not contain any previously set | ||
350 | value. | ||
351 | </p> | ||
352 | <p> | ||
353 | You're advised to call this function only when needed and as close as | ||
354 | possible after the return of the related C function. The | ||
355 | <tt>errno</tt> value is preserved across hooks, memory allocations, | ||
356 | invocations of the JIT compiler and other internal VM activity. The same | ||
357 | applies to the value returned by <tt>GetLastError()</tt> on Windows, but | ||
358 | you need to declare and call it yourself. | ||
359 | </p> | ||
360 | |||
339 | <h3 id="ffi_string"><tt>str = ffi.string(ptr [,len])</tt></h3> | 361 | <h3 id="ffi_string"><tt>str = ffi.string(ptr [,len])</tt></h3> |
340 | <p> | 362 | <p> |
341 | Creates an interned Lua string from the data pointed to by | 363 | Creates an interned Lua string from the data pointed to by |
diff --git a/src/lib_ffi.c b/src/lib_ffi.c index 27996f0e..321de499 100644 --- a/src/lib_ffi.c +++ b/src/lib_ffi.c | |||
@@ -6,6 +6,8 @@ | |||
6 | #define lib_ffi_c | 6 | #define lib_ffi_c |
7 | #define LUA_LIB | 7 | #define LUA_LIB |
8 | 8 | ||
9 | #include <errno.h> | ||
10 | |||
9 | #include "lua.h" | 11 | #include "lua.h" |
10 | #include "lauxlib.h" | 12 | #include "lauxlib.h" |
11 | #include "lualib.h" | 13 | #include "lualib.h" |
@@ -541,6 +543,12 @@ LJLIB_CF(ffi_offsetof) | |||
541 | return 0; | 543 | return 0; |
542 | } | 544 | } |
543 | 545 | ||
546 | LJLIB_CF(ffi_errno) | ||
547 | { | ||
548 | setintV(L->top++, errno); | ||
549 | return 1; | ||
550 | } | ||
551 | |||
544 | LJLIB_CF(ffi_string) LJLIB_REC(.) | 552 | LJLIB_CF(ffi_string) LJLIB_REC(.) |
545 | { | 553 | { |
546 | CTState *cts = ctype_cts(L); | 554 | CTState *cts = ctype_cts(L); |