lovr/src/util.h

48 lines
1.6 KiB
C
Raw Normal View History

2016-11-19 09:28:01 +00:00
#include "vendor/vec/vec.h"
#include "vendor/map/map.h"
2016-07-07 07:04:24 +00:00
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
2016-09-30 06:18:51 +00:00
#ifndef UTIL_TYPES
#define UTIL_TYPES
2016-10-04 22:05:34 +00:00
#define MAX(a, b) a > b ? a : b
#define MIN(a, b) a < b ? a : b
#define LOVR_COLOR(r, g, b, a) ((a << 0) | (b << 8) | (g << 16) | (r << 24))
#define LOVR_COLOR_R(c) (c >> 24 & 0xff)
#define LOVR_COLOR_G(c) (c >> 16 & 0xff)
#define LOVR_COLOR_B(c) (c >> 8 & 0xff)
#define LOVR_COLOR_A(c) (c >> 0 & 0xff)
2016-11-19 07:41:23 +00:00
#define luax_checklovrtype(L, i, T) *(T**) luaL_checkudata(L, i, #T);
#define luax_pushlovrtype(L, T, x) \
T** u = (T**) lua_newuserdata(L, sizeof(T**)); \
luaL_getmetatable(L, #T); \
lua_setmetatable(L, -2); \
*u = x;
typedef struct ref {
void (*free)(const struct ref* ref);
int count;
} Ref;
#define containerof(ptr, type) ((type*)((char*)(ptr) - offsetof(type, ref)))
2016-09-30 06:18:51 +00:00
typedef vec_t(unsigned int) vec_uint_t;
#endif
2016-07-07 07:04:24 +00:00
void error(const char* format, ...);
2016-11-08 09:42:31 +00:00
unsigned char* loadImage(void* data, size_t size, int* w, int* h, int* n, int channels);
2016-07-07 07:04:24 +00:00
void luaRegisterModule(lua_State* L, const char* name, const luaL_Reg* module);
2016-11-19 07:41:23 +00:00
void luaRegisterType(lua_State* L, const char* name, const luaL_Reg* functions);
2016-08-01 00:21:04 +00:00
int luaPreloadModule(lua_State* L, const char* key, lua_CFunction f);
2016-11-08 22:15:37 +00:00
const char* map_int_find(map_int_t *map, int value);
void* luax_checkenum(lua_State* L, int index, map_int_t* map, const char* typeName);
void* luax_optenum(lua_State* L, int index, const char* fallback, map_int_t* map, const char* typeName);
2016-11-19 07:41:23 +00:00
void* lovrAlloc(size_t size, void (*destructor)(const Ref* ref));
void lovrRetain(const Ref* ref);
void lovrRelease(const Ref* ref);
int luax_destroylovrtype(lua_State* L);