-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.lua
More file actions
executable file
·53 lines (44 loc) · 1.67 KB
/
hello.lua
File metadata and controls
executable file
·53 lines (44 loc) · 1.67 KB
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
53
#!/usr/bin/env luajit
--[[
Barebones example of FBInk usage through LuaJIT's FFI module
--]]
local ffi = require("ffi")
local C = ffi.C
-- Load the prepared declarations (built from FBInk/ffi/fbink_decl.c via https://github.com/koreader/ffi-cdecl)
local _ = require("ffi/fbink_h")
-- And load the actual FBInk library...
-- Either by specifying a filepath:
--local FBInk = ffi.load("lib/libfbink.so.1.0.0")
-- Or by letting the dynamic loader figure it out ;).
local FBInk = ffi.load("fbink")
-- Let's check which FBInk version we're using...
print("Loaded FBInk " .. ffi.string(FBInk.fbink_version()))
-- And now we're good to go! Let's print "Hello World" in the center of the screen...
-- Setup the config...
-- NOTE: Because this is a struct, we can rely on an implicit cdata<&FBInkConfig> conversion
-- when passed to a C function that expects a cdata<FBInkConfig*>.
-- c.f., https://luajit.org/ext_ffi_semantics.html
-- This allows a less unwieldy syntax than the usual "array of one" approach necessary for outargs pointers.
local fbink_cfg = ffi.new("FBInkConfig")
fbink_cfg.is_centered = true
fbink_cfg.is_halfway = true
-- Open the FB...
local fbfd = FBInk.fbink_open()
if fbfd == -1 then
print("Failed to open the framebuffer, aborting . . .")
os.exit(-1)
end
-- Initialize FBInk...
if FBInk.fbink_init(fbfd, fbink_cfg) < 0 then
print("Failed to initialize FBInk, aborting . . .")
os.exit(-1)
end
-- Do stuff!
if FBInk.fbink_print(fbfd, "Hello World", fbink_cfg) < 0 then
print("Failed to print that string!")
end
-- And now we can wind things down...
if FBInk.fbink_close(fbfd) < 0 then
print("Failed to close the framebuffer, aborting . . .")
os.exit(-1)
end