4
votes

I downloaded LuaEdit to use as an IDE and debug tool however I'm having trouble using it for even the simplest things. I've created a solution with 2 files in it, all of which are stored in the same folder. My files are as follows:

--startup.lua

require("foo")

test("Testing", "testing", "one, two, three")


--foo.lua

foo = {}

print("In foo.lua")

function test(a,b,c) print(a,b,c) end

This works fine when in my C++ compiler when accessed through some embed code, however when I attempt to use the same code in LuaEdit, it crashes on line 3 require("foo") with an error stating:

module 'foo' not found:
no field package.preload['foo']
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\lua\foo\init.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo\init.lua'
no file '.\foo.lua'
no file 'C:\Program Files (x86)\LuaEdit 2010\foo.dll'
no file 'C:\Program Files (x86)\LuaEdit 2010\loadall.dll'
no file '.\battle.dll'

I have also tried creating these files prior to adding them to a solution and still get the same error. Is there some setting I'm missing? It would be great to have an IDE/debugger but it's useless to me if it can't run linked functions.

2

2 Answers

3
votes

The issue is probably that your Lua files are not on the path in package.path (for C files this is package.cpath).

My guess is that the LuaEdit program is not launched in the directory you have your files in, and hence does not have a match for eg .\foo.lua.

You have 3 simple solutions to this (from dumb to smarter):

  • Find out what path LuaEdit considers as ./ and put your files there.
  • Open up a terminal in the right directory (the one containing your files), and run LuaEdit from there.
  • Add the path the files are on to package.path and package.cpath before doing any require's
3
votes

You may need to put:

lua package.path = package.path..";c:/path/to/my/files/?.lua"

at the beginning of your files before any require (as jpjacobs indicated). I couldn't find any way to provide this from LuaEdit itself. It appears it runs the script using its full path, but keeps its current dir set to whatever it was when the IDE was started. If you run LuaEdit using full path from your application folder, it should work fine even without package.path changes.

While the IDE itself works fine with its own modules/libraries, it doesn't mean it makes them available to the application it runs.

(shameless plug) If you're still not happy with LuaEdit, I'd offer ZeroBrane Studio Lua IDE as an alternative, It's based on the same wxLua framework, but provides a bit more functionality and doesn't have this particular issue you're facing. It also supports remote debugging, so you should be able to debug your Lua scripts directly from your application.