FlightControl-Master / MOOSE

Mission Object Oriented Scripting Environment (MOOSE) for lua mission scripting design in DCS World
http://flightcontrol-master.github.io/MOOSE/
GNU General Public License v3.0
290 stars 94 forks source link

Automatic dynamic loading of development files in static Moose.lua #2085

Closed kaltokri closed 8 months ago

kaltokri commented 8 months ago

I found a way to combine the static and dynamic include of Moose. We need to add the code below on top of the generated Moose.lua. This will be added to each demo mission and then it will load automatically the individual developer files if the user has added a junction link to his DCS install directory pointing to the MOOSE repo. This will simplify demo mission testing and maintaining a lot.

Step to integrate:

-- Try to load Moose as individual script files
-- This method is used by Moose developers
ModuleLoader = 'Scripts/Moose/Modules.lua'

local f=io.open(ModuleLoader,"r")
if f~=nil then
  io.close(f)

  env.info( '*** MOOSE DYNAMIC INCLUDE START *** ' )

  local base = _G

  __Moose = {}

  __Moose.Include = function( IncludeFile )
    if not __Moose.Includes[ IncludeFile ] then
      __Moose.Includes[IncludeFile] = IncludeFile
      local f = assert( base.loadfile( IncludeFile ) )
      if f == nil then
        error ("Moose: Could not load Moose file " .. IncludeFile )
      else
        env.info( "Moose: " .. IncludeFile .. " dynamically loaded." )
        return f()
      end
    end
  end

  __Moose.Includes = {}

  __Moose.Include( 'Scripts/Moose/Modules.lua' )
  BASE:TraceOnOff( true )
  env.info( '*** MOOSE INCLUDE END *** ' )

  -- Skip the static part of this file completly
  do return end
end

-- Individual Moose files are not found. Use the static code below.