#include <stdlib.h>
#include <malloc.h>
#include <pspdisplay.h>
#include <psputils.h>
#include <pspgu.h>
#include <pspgum.h>
#include <string.h>
#include <oslib/oslib.h>
#include <machine/fastmath.h>
//#include "veraMono.cpp"

#include "pge/pgeFont.h"
#include "share.h"
UserdataStubs(Font, pgeFont*)
static int Font_load(lua_State *L) {

	pgeFont *font = pgeFontLoad(luaL_checkstring(L, 1), luaL_checknumber(L, 2), PGE_FONT_SIZE_PIXELS, 256);
	pgeFont** luaFont = pushFont(L);
	*luaFont = font;
	return 1;
}
static int Font_print(lua_State *L) {

	pgeFont* font = *toFont(L, 1);
	char *colorstr = luaL_checkstring(L, 5);
	unsigned int color;
	sscanf (colorstr,"%x",&color);
	pgeFontActivate(font);
	pgeFontPrint(font, luaL_checknumber(L, 2), luaL_checknumber(L, 3), color, luaL_checkstring(L, 4));
	return 1;
}
static int Font_free(lua_State *L) {
	pgeFont* font = *toFont(L, 1);
	pgeFontUnload(font);
	return 0;
}
static const luaL_reg Font_methods[] = {
	{"load", Font_load},
	{"print", Font_print},
	{0,0}
};
static const luaL_reg Font_meta[] = {
	{"__gc", Font_free},
	{0,0}
};
UserdataRegister(Font, Font_methods, Font_meta)
void font_init(lua_State *L) {
	Font_register(L);
}