Jump to content

Lua advice - Splitting huge script into main script + multiple 'modules' - log/env is nil?!


Recommended Posts

I've been working on my own 'superscript' and at 17000 lines long (with lots of comments) it's too unwieldy and for debugging I want to be able to remove sections in case of 'contamination'.

I'm still learning Lua and it's intricacies but what I came up with was my main script would be called by the mission at MISSION START and then any 'modules' I wanted to run would be specified by 'require' at the top. 

Here's what I have in cut down form:

package.path = package.path .. ';C:\\TEMPESTsLuaControls\\Modules\\?.lua'

local TLO = require "TLO"
-- local TPH = require "TPH"
-- local TMB = require "TMB"

TLC = { ["Version"] = "2.0.0" }
  
world.addEventHandler(TLC)

TLO.LogWrite("TLC", "INFO", "Initialisation Complete. Version %s", self.Version)

The first 'module' - my logging / output module, also is supposed to exist in the Lua 'mission' environment, just like the main script, but

log.write

no longer works. 

Even worse

env.info

doesn't work either.

I get the 'log' or 'env' is nil error.

err.jpg

 

Here's how my 'modules' are defined:

module("TLO")

TLO = { ["Version"] = "2.0.0" }

function TLO.LogWrite(source, level, message, ...)

    log.write(source, log[level:upper()], string.format(message, ...))

end

function TLO.InitialiseTLO()

  TLO.LogWrite("TLO", "INFO", "Initialisation Complete. Version %s", TLO.Version)

end

TLO.InitialiseTLO()

I know I'm missing or haven't understood some core part of Lua but I've spent two days on this and even got a copy of 'Programming in Lua 2nd Edition' on the way from Amazon, but I'm lost at where I've gone wrong.

 

 

 

 


Edited by Elphaba
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...