3

I have a some Lua code that contains my business logic, which I would like to run inside .NET using NLua.

Some of my lua file currently use the "require" keyword in order to reference functions in other files. Now, this works fine if I run the code using e.g. ZeroBrane Studio. However, once I use "DoFile" to load the code into NLua, I get some "Module not found" errors.

My question is; can I use the concept of "require", when running the code inside NLua? If not, would I then need to remove these lines, before running DoFile on the files (and of course make sure to run the files in the correct order)?

Update: I think perhaps I simply need to add my Lua file folder to the package.path. I solved it by doing a DoString("package.path = '<my_path>' .. package.path"); Is this "best practise"?

Kristian Vinther
  • 578
  • 2
  • 6
  • 15

1 Answers1

1

The root directory location the search starts in is the location where your executable is running, not where the file you ran DoString on is located.

Here are some examples of locations NLua require will look, using heaps.lua as an example file:

no file './heaps.lua'
no file './heaps/init.lua'
no file './lua/heaps.lua'

Example:

Executable path C:\foo\bar.exe

Script path C:\baz\qux.lua

qux.lua has a require for heaps, NLua will search in C:\foo\ for heaps and will not search C:\baz\.

Nifim
  • 4,758
  • 2
  • 12
  • 31