summaryrefslogtreecommitdiff
path: root/src/texture/texture.c
diff options
context:
space:
mode:
authorsanine-a <sanine.not@pm.me>2020-10-31 14:01:55 -0500
committersanine-a <sanine.not@pm.me>2020-10-31 14:01:55 -0500
commit50d8b05f588d019a8a5ae1a76d22677b10553167 (patch)
tree6130b4c9367a663f64a9debba47625439e5fb997 /src/texture/texture.c
parenta9f0521984f43f3048d3e0fec15082916e7f8331 (diff)
add basic texture bindings
Diffstat (limited to 'src/texture/texture.c')
-rw-r--r--src/texture/texture.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/texture/texture.c b/src/texture/texture.c
index 591ee11..1bb798a 100644
--- a/src/texture/texture.c
+++ b/src/texture/texture.c
@@ -1,6 +1,59 @@
#include "texture.h"
-enum honey_texture_result honey_texture_new(honey_texture* texture,
+static int honey_lua_texture_new(lua_State* L)
+{
+ honey_texture* texture = lua_newuserdata(L, sizeof(honey_texture));
+ return 1;
+}
+
+static int honey_lua_texture_load(lua_State* L)
+{
+ honey_texture* texture;
+ char* texture_path;
+ bool use_alpha;
+ honey_lua_parse_arguments(L, 3,
+ HONEY_USERDATA, &texture,
+ HONEY_STRING, &texture_path,
+ HONEY_BOOLEAN, &use_alpha);
+ enum honey_texture_result result = honey_texture_load(texture, texture_path, use_alpha);
+ if (result != TEXTURE_OK) {
+ char* error;
+ honey_format_string(&error,
+ "failed to load '%s'",
+ texture_path);
+ lua_pushstring(L, error);
+ free(error);
+ lua_error(L);
+ }
+
+ return 0;
+}
+
+static int honey_lua_texture_use(lua_State* L)
+{
+ honey_texture* texture;
+ int texture_unit;
+ honey_lua_parse_arguments(L, 2,
+ HONEY_USERDATA, &texture,
+ HONEY_INTEGER, &texture_unit);
+ honey_texture_use(*texture, texture_unit);
+ return 0;
+}
+
+void honey_setup_texture(lua_State* L)
+{
+ honey_lua_element texture_elements[] = {
+ { "new", HONEY_FUNCTION, { .function = honey_lua_texture_new } },
+ { "load", HONEY_FUNCTION, { .function = honey_lua_texture_load } },
+ { "use", HONEY_FUNCTION, { .function = honey_lua_texture_use } },
+ };
+
+ honey_lua_create_table(L, texture_elements, 3);
+}
+
+/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+
+enum honey_texture_result honey_texture_load(honey_texture* texture,
char* texture_path,
bool alpha_channel) {
unsigned int texture_id;