int lua_import(stream_t* stream, const uuid_t uuid_given) { uuid_t uuid = uuid_given; string_const_t path; string_const_t extension; bool store_import = false; luaimport_dump_t dump = {0, 0}; int ret; path = stream_path(stream); extension = path_file_extension(STRING_ARGS(path)); if (!string_equal_nocase(STRING_ARGS(extension), STRING_CONST("lua"))) return -1; if (uuid_is_null(uuid)) uuid = resource_import_map_lookup(STRING_ARGS(path)).uuid; if (uuid_is_null(uuid)) { uuid = uuid_generate_random(); store_import = true; } if (store_import) { uuid_t founduuid = resource_import_map_store(STRING_ARGS(path), uuid, uint256_null()); if (uuid_is_null(founduuid)) { log_warn(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to open import map file to store new resource")); return -1; } uuid = founduuid; } if ((ret = lua_import_stream(stream, uuid, &dump)) < 0) goto exit; if ((ret = lua_import_output(uuid, &dump)) < 0) goto exit; resource_import_map_store(STRING_ARGS(path), uuid, stream_sha256(stream)); exit: memory_deallocate(dump.bytecode); return ret; }
int render_import(stream_t* stream, const uuid_t uuid_given) { renderimport_type_t type = IMPORTTYPE_UNKNOWN; renderimport_type_t guess = IMPORTTYPE_UNKNOWN; uuid_t uuid = uuid_given; string_const_t path; string_const_t extension; int ret; bool store_import = false; path = stream_path(stream); extension = path_file_extension(STRING_ARGS(path)); if (string_equal_nocase(STRING_ARGS(extension), STRING_CONST("shader"))) guess = IMPORTTYPE_SHADER; else if (string_equal_nocase(STRING_ARGS(extension), STRING_CONST("program"))) guess = IMPORTTYPE_PROGRAM; type = render_import_shader_guess_type(stream); if ((type == IMPORTTYPE_UNKNOWN) && (guess != IMPORTTYPE_UNKNOWN)) type = guess; if (type == IMPORTTYPE_UNKNOWN) return -1; if (uuid_is_null(uuid)) uuid = resource_import_lookup(STRING_ARGS(path)).uuid; if (uuid_is_null(uuid)) { uuid = uuid_generate_random(); store_import = true; } if (store_import) { uuid_t founduuid = resource_import_map_store(STRING_ARGS(path), uuid, uint256_null()); if (uuid_is_null(founduuid)) { log_warn(HASH_RESOURCE, WARNING_SUSPICIOUS, STRING_CONST("Unable to open import map file to store new resource")); return -1; } uuid = founduuid; } switch (type) { case IMPORTTYPE_PROGRAM: ret = render_import_program(stream, uuid); break; case IMPORTTYPE_SHADER: ret = render_import_shader(stream, uuid); break; case IMPORTTYPE_GLSL_VERTEXSHADER: ret = render_import_glsl_vertexshader(stream, uuid); break; case IMPORTTYPE_GLSL_PIXELSHADER: ret = render_import_glsl_pixelshader(stream, uuid); break; case IMPORTTYPE_UNKNOWN: default: return -1; } if (ret == 0) resource_import_map_store(STRING_ARGS(path), uuid, stream_sha256(stream)); return ret; }