Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a018346
commit c7c6fc7
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local ffi = require "ffi" | ||
local fs = require "fs" | ||
|
||
-- Feed the header to ffi | ||
ffi.cdef(fs.readFileSync("uvffi.h")) | ||
-- Cache the C namespace object | ||
local C = ffi.C | ||
-- Create our lua module | ||
local uv = {} | ||
|
||
local function uvCheck(err) | ||
if err.code == 0 then return end | ||
local name = ffi.string(C.uv_err_name(err)) | ||
local message = ffi.string(C.uv_strerror(err)) | ||
error(name .. ": " .. message) | ||
end | ||
|
||
function uv.getProcessTitle() | ||
local buffer = ffi.new("char[MAX_TITLE_LENGTH]") | ||
uvCheck(C.uv_get_process_title(buffer, C.MAX_TITLE_LENGTH)) | ||
return ffi.string(buffer) | ||
end | ||
|
||
function uv.setProcessTitle(title) | ||
uvCheck(C.uv_set_process_title(title)) | ||
end | ||
|
||
p(uv.getProcessTitle()) | ||
uv.setProcessTitle("FOOMONKEY") | ||
p(uv.getProcessTitle()) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* uvffi.h */ | ||
enum { MAX_TITLE_LENGTH = 8192 } | ||
struct uv_err_s { int code; int sys_errno_; }; | ||
typedef struct uv_err_s uv_err_t; | ||
uv_err_t uv_get_process_title(char* buffer, size_t size); | ||
uv_err_t uv_set_process_title(const char* title); | ||
const char* uv_strerror(uv_err_t err); | ||
const char* uv_err_name(uv_err_t err); |