forked from cloudwu/lua-bgfx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgfx_interface.h
51 lines (45 loc) · 1.34 KB
/
bgfx_interface.h
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
#ifndef lua_bgfx_interface_h
#define lua_bgfx_interface_h
#include <lua.h>
#include <lauxlib.h>
#include <bgfx/c99/bgfx.h>
static bgfx_interface_vtbl_t* bgfx_inf_ = 0;
static inline void
init_interface(lua_State* L) {
if (bgfx_inf_) {
return;
}
#ifdef BGFX_STATIC_LINK
bgfx_interface_vtbl_t* inf = bgfx_get_interface(BGFX_API_VERSION);
if (inf == NULL) {
luaL_error(L, "BGFX_API_VERSION (%d) mismatch.", BGFX_API_VERSION);
return;
}
bgfx_inf_ = inf;
lua_pushcfunction(L, (lua_CFunction)bgfx_get_interface);
lua_setfield(L, LUA_REGISTRYINDEX, "BGFX_GET_INTERFACE");
#else
if (LUA_TFUNCTION != lua_getfield(L, LUA_REGISTRYINDEX, "BGFX_GET_INTERFACE")) {
luaL_error(L, "BGFX_GET_INTERFACE is missing.");
return;
}
lua_CFunction fn = lua_tocfunction(L, -1);
if (fn == NULL) {
luaL_error(L, "BGFX_GET_INTERFACE is not a C function.");
return;
}
bgfx_interface_vtbl_t* inf = ((PFN_BGFX_GET_INTERFACE)fn)(BGFX_API_VERSION);
if (inf == NULL) {
luaL_error(L, "BGFX_API_VERSION (%d) mismatch.", BGFX_API_VERSION);
return;
}
bgfx_inf_ = inf;
lua_pop(L, 1);
#endif
}
#define BGFX(api) bgfx_inf_->api
#define BGFX_ENCODER(api, encoder, ...) (encoder ? (BGFX(encoder_##api)( encoder, ## __VA_ARGS__ )) : BGFX(api)( __VA_ARGS__ ))
#ifdef EXPORT_BGFX_INTERFACE
bgfx_interface_vtbl_t* ibgfx(){return bgfx_inf_;}
#endif //EXPORT_BGFX_INTERFACE
#endif