#include #include #include "util/util.h" #include "import.h" #define TINYOBJ_LOADER_C_IMPLEMENTATION #include void read_file(void *ctx, const char *filename, int is_mtl, const char *obj_filename, char **buf, size_t *len) { lua_State *L = ctx; FILE *f = fopen(filename, "rb"); if (f == NULL) { luaL_error(L, "failed to open file \"%s\"", filename); } fseek(f, 0, SEEK_END); *len = ftell(f); fseek(f, 0, SEEK_SET); *buf = malloc(*len); fread(*buf, *len, 1, f); fclose(f); } static void push_float_array(lua_State *L, float *arr, size_t len) { lua_createtable(L, len, 0); int tbl = lua_gettop(L); for (int i=0; i