Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
LamboCreeper

Module can't be found but file exists at location?

Question

Hey,

I haven't worked with Lua in a while and recently my friends and I started a new modded game. I'm currently trying to require another file from another, and to my knowledge have done it to how the syntax describes. However, OpenOS is giving me an error stating the following:

tyGEc1Su.png

However, when running the cd command it states that core.lua does indeed exist in the directory /home/

VatJ1M-3.png

This is my code:

-- core.lua

function catch(inp)
	return inp[1]
end

function try(inp)
	status, res = pcall(inp[1])
	if not status then
		inp[2](res)
	end
	return res
end

-- test.lua

function dir()
   local str = debug.getinfo(2, "S").source:sub(2)
   return str:match("(.*/)")
end

-- this is where it breaks:
require(dir() .. "core.lua")

local http

core.try {	
	function()
		http = require("socket.http")
		local body, code = http.request('https://raw.githubusercontent.com/rxi/json.lua/master/json.lua')
		local f = assert(io.open('modules/json.lua', 'wb'))
		f:write(body)
		f:close()
		print('Successfully downloaded json.lua module.')
	end, core.catch {
		function(err)
			print('Caught Error: ' .. err)
		end
	}
}

If someone could please explain to me what I am doing wrong and more specifically how to fix the issue it would be greatly appreciated.

Link to post
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.