tags:

views:

601

answers:

2

I have 3 lua files, Init.lua, FreeCamera.lua and Camera.lua ,

init.lua calls require "Core.Camera.FreeCamera"

Free Camera:

module(...)
require "Core.Camera.Camera"

local M = {}
FreeCamera = M

M = Class( Camera )
function M:__constructor(x,y,z)
  self.Active = false
  self.x = x
  self.y = y
  self.z = z
end

and

module(...)

local M = {}
Camera = M

M = Class()

function M:__constructor(x,y,z)
  self.Active = false
  self.x = x
  self.y = y
  self.z = z
end

FreeCamera "inherits" Camera kind of. I am trying to require FreeCamera in my init file and I am getting this:

..\Content\Modules\Core\Camera\FreeCamera.lua:12: attempt to call global 'require' (a nil value). Any idea Why? Am I using require the right way? Clearly it is getting into FreeCamera.lua, which is great, but it gets stuck on the next require.

+3  A: 

The module function creates a new empty environment and so require is not found when called. Try calling require before calling module.

lhf
That seems to have done the trick, now it says Class() is nil, but if i change that from a global, to require, it should work according to what you are saying.
Joe
+4  A: 
Norman Ramsey
perfect! i noticed this in the critique page on the module function, I am glad to know that it is good style!!
Joe