3

I have a situation where I need to use two modules... both of which load / reference another module. So I'm getting an error about a loop.

Here's the code in module1:

require("posix")
posix.setenv("PATH", "/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin")

and in module 2 I have the same thing:

require("posix")
local ts = posix.stat(spath, "ctime")

I found this post: Lua: How to avoid Circular Requires

I tried to apply what the above post said and I changed my logic in both modules to look like this:

posix = posix or require("posix")

But I'm still getting the error message. Any suggestions would be appreciated.

EDIT 1

tester.lua

local main =require("main")

main.lua

module (..., package.seeall)
-- Load libraries
require("commonfunctions")
require("luasql.postgres")
require("session")

commonfunctions.lua

posix = posix or require "posix"

session.lua

posix = posix or require "posix"

Error Message

lua: /usr/share/acf/lib//session.lua:15: loop or previous error loading module 'posix'
stack traceback:
        [C]: in function 'require'
        /usr/share/lib//session.lua:15: in main chunk
        [C]: in function 'require'
        /usr/share/myapp/main.lua:10: in main chunk
        [C]: in function 'require'
        /usr/share/lua/5.1/posix.lua:2: in main chunk
        [C]: in function 'require'
        /usr/share/acf/lib//commonfunctions.lua:4: in main chunk
        [C]: in function 'require'
        ./kamfmfm-model.lua:3: in main chunk
        [C]: in function 'require'
        tester.lua:6: in main chunk
        [C]: ?
Community
  • 1
  • 1
dot
  • 14,928
  • 41
  • 110
  • 218
  • Which error message are you getting? What are the modules named? – lhf Dec 18 '13 at 15:11
  • lhf, please check out Edit 1 of my post. Thank you! – dot Dec 18 '13 at 15:20
  • It's not a loop problem like in that SO post you refer to. You don't have A require B and B require A. Does the problem go away if 'main' doesn't require 'session'? Have you tried running each module individually? – Oliver Dec 18 '13 at 16:05

0 Answers0