Search code examples
lualuajit

Do file only once in Lua


I was wondering if there's a way to do a lua file only once and have any subsequent attempts to do that lua file will result in a no-op.

I've already thought about doing something akin to C++ header's #if/else/endif trick. I'm wondering if there's a standard way to implement this.

James


Solution

  • well, require pretty much does that.

    require "file" -- runs "file.lua"
    require "file" -- does not run the "file" again