forked from Waqar144/lite-odin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_renderer_font.odin
More file actions
70 lines (57 loc) · 1.84 KB
/
api_renderer_font.odin
File metadata and controls
70 lines (57 loc) · 1.84 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import "base:runtime"
import lua "vendor:lua/5.4"
f_load :: proc "c" (L: ^lua.State) -> i32 {
context = runtime.default_context()
filename: cstring = lua.L_checkstring(L, 1)
size: f32 = cast(f32)lua.L_checknumber(L, 2)
self: ^^RenFont = cast(^^RenFont)lua.newuserdata(L, size_of(^RenFont))
lua.L_setmetatable(L, API_TYPE_FONT)
self^ = ren_load_font(filename, size)
if (self^ == nil) {
lua.L_error(L, "failed to load font")
}
return 1
}
f_set_tab_width :: proc "c" (L: ^lua.State) -> i32 {
context = runtime.default_context()
self: ^^RenFont = cast(^^RenFont)lua.L_checkudata(L, 1, API_TYPE_FONT)
n := lua.L_checknumber(L, 2)
ren_set_font_tab_width(self^, i32(n))
return 0
}
f_gc :: proc "c" (L: ^lua.State) -> i32 {
self: ^^RenFont = cast(^^RenFont)lua.L_checkudata(L, 1, API_TYPE_FONT)
context = runtime.default_context()
if (self^ != nil) {rencache_free_font(self^)}
return 0
}
f_get_width :: proc "c" (L: ^lua.State) -> i32 {
self: ^^RenFont = cast(^^RenFont)lua.L_checkudata(L, 1, API_TYPE_FONT)
text: cstring = lua.L_checkstring(L, 2)
context = runtime.default_context()
lua.pushnumber(L, cast(lua.Number)ren_get_font_width(self^, text))
return 1
}
f_get_height :: proc "c" (L: ^lua.State) -> i32 {
self: ^^RenFont = cast(^^RenFont)lua.L_checkudata(L, 1, API_TYPE_FONT)
lua.pushnumber(L, cast(lua.Number)ren_get_font_height(self^))
return 1
}
// odinfmt: disable
@(private="file")
lib := []lua.L_Reg {
{ "__gc", f_gc },
{ "load", f_load },
{ "set_tab_width", f_set_tab_width },
{ "get_width", f_get_width },
{ "get_height", f_get_height },
}
// odinfmt: enable
luaopen_renderer_font :: proc "c" (L: ^lua.State) -> i32 {
lua.L_newmetatable(L, API_TYPE_FONT)
lua.L_setfuncs(L, raw_data(lib), 0)
lua.pushvalue(L, -1)
lua.setfield(L, -2, "__index")
return 1
}