Search code examples
luarequire

Lua (require) invoke an not intended print of required file name


When require is called in testt.lua which is one of two files the return is movee and movee.lua.

movee are for the most part a class to be required, but should be able to accept to be called direct with parameter.

movee.lua

local lib = {} --this is class array

function lib.moveAround( ... )
    for i,direction in ipairs(arg) do
        print(direction)
    end
end

function lib.hello()
    print("Hello water jump")
end

lib.moveAround(...)

return lib

testt.la

local move = require("movee")

Expected result is not to call lib.moveAround or print of file name when require is called.


Solution

  • Solved by replacing

    lib.moveAround(...)
    

    with

    local argument = {...}
    if argument[1] ~= "movee" and argument[2] ~= "movee" then
        lib.moveAround(...)
    end