Is here any alternative to the default Lua „io“ library?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Hi,
    i need to fork this github repistory to be able to use it with www.webscript.io

  2. What is the issue? Include screenshots / videos if possible!
    I see that i need the Lua default „io“ library, but idk how to use it (see below why)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I readed this topic where @TaslemGuy say that Roblox removes this library, but it not helped me out.

I cant use the code as i need the io library, but Roblox removed it so i need help to find a alternative. This is the github repistory

1 Like

You can’t. io stands for input/output. It allows you to read files and such. In Roblox, you can’t and don’t need it. Your option is to not write this in Roblox.

1 Like

After taking a read of the code, it seems to only open and read files which could be possibly replicated with the use of require and ModuleScripts.

Simply return your OBJ data from the ModuleScript:

return "<data>";

Then, you’ll need to update the reading segments to use require & split the data by “\n” (new line) for a table to iterate through.

Here’s an example of the updated loadObj:

local function loadObj(filePath, settings)
	settings = settings or {
		scale = 1;
	};

	local active_material = "";

	local active_object, active_group = MinimalObjModel(), nil;
	---------------------------------------------------------------------------
	local obj_Operations = {
		--[[
			# is a comment, skip these
		--]]
		['#'] = function(model, token) end,

		--[[
			mtllib denotes a required mtl file
		--]]
		['mtllib'] = function(model, token)
			model.material_file_name = token[1];
		end,

		--[[
			usemtl tells what material to use for the faces
		--]]
		['usemtl'] = function(model, token)
			active_material = token[1];
		end,

		--[[
			v denotes vertex
		--]]
		['v'] = function(model, token, settings)
			local v = Vertex(token[1] * settings.scale, token[2] * settings.scale, token[3] * settings.scale, token[4]);

			model.vertices[#model.vertices+1] = v
			active_object.vertices[#model.vertices] = true;
		end,

		--[[
			vt denotes texture coordinates(UV)
		--]]
		['vt'] = function(model, token, settings)
			local uv = UV(token[1] * settings.scale, token[2] * settings.scale, token[3]);

			model.uvs[#model.uvs+1] = uv;
			active_object.uvs[#model.uvs] = true;
		end,

		--[[
			vn denotes normal
		--]]
		['vn'] = function(model, token, settings)
			local normal = Normal(token[1] * settings.scale, token[2] * settings.scale, token[3] * settings.scale);

			model.normals[#model.normals+1] = normal;
			active_object.normals[#model.normals] = true;
		end,

		--[[
			vp denotes free form geometry
		--]]
		['vp'] = function(model, token, settings)
			local vp = free_form(token[1], token[2], token[3]);

			model.space_vertices[#model.space_vertices+1] = vp;
			active_object.space_vertices[#model.space_vertices] = true;
		end,

		--[[
			f denotes faces
		--]]
		['f'] = function(model, token, settings)
			local face = _readFace(model, token, active_material);
			model.faces[#model.faces+1] = face;

			active_object.faces[#model.faces] = true;

			model.poly_count = model.poly_count+1;
		end,

		--[[
			o denotes object
		--]]
		['o'] = function(model, token, settings)
			local object = MeshObjectModel(token[1], active_group);

			model.objects[#model.objects+1] = object;
			active_object = object;
		end,

		--[[
			g denotes group
		--]]
		['g'] = function(model, token)
			local group = GroupModel(token[1]);

			model.groups[#model.groups+1] = group;
			active_group = group;
		end,
	};
	---------------------------------------------------------------------------
	local data = require(ModuleScript) --// UPDATED

	local model = ObjModel();

	for _, line in ipairs(string.split(data, " ")) do --// UPDATED
		if (line ~= "") then
			local token = {};
			for tk in line:gmatch("%S+") do
				token[#token+1] = tk;
			end

			local identifier = token[1];
			if (obj_Operations[identifier]) then
				table.remove(token, 1);
				obj_Operations[identifier](model, token, settings);
			end
		end
	end

	return model;
end

Of course, you’ll need to remove the assertion at the top the Script:

assert(io, "Requires io library to function!");
2 Likes

By the way, just a note: you don’t have to add a semi colon after every line in Lua because Lua knows spacing by itself unless your creating tables or dictionaries which is the only case where you would need to use a coma or semi colon.

2 Likes

how to return my OBJ data? Do i need to open my OBJ model as file and insert it in my modelscript? But thanks for this great reply

They are probably aware of this. Some people do it for consistency or cleanness of code.

I personally do it sometimes given how I code multiple other languages where ; is required and so it’s just a habit.

2 Likes

Thanks to you all, i think that i now can resolve my problem, but i still have a question: So its really impossible to have the io library, still when i try to use a third party service thanks the HttpsService?