Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 616961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:22:59+00:00 2026-05-13T18:22:59+00:00

I have implemented OOP in my lua environment but it doesnt seem to be

  • 0

I have implemented OOP in my lua environment but it doesnt seem to be working.

I think it has something to do with how i am handling the __index and my improper use of require and module but I’m not 100% sure.

Here is the code:

    Class = function( prototype )
    local derived = {}
    local derivedMT = {
        --When indexing into a derived class, check the base class as well
        __index = prototype,

        --When invoking a class, return an instance
        __call = function( proto, ... )
            local instance = {}
            local instanceMT = {
                --When indexing into an instance, check the class hierarchy as well.
                __index = derived,
                --Calling instances is a no-no!
                __call = function() 
                    print( "WARNING! Attempt to invoke an instance of a class!" )
                    print( debug.traceback() )
                    return instance
                end,                
            }
            setmetatable( instance, instanceMT )

            if ( instance.__constructor ) then
                instance:__constructor( ... )
            end

            return instance
        end,
    }
    setmetatable( derived, derivedMT )
    return derived  
end

And here is how I use it, the nil reference is a call to a base class function, that is the error/problem im having is it seems like the base class isn’t being referenced.

require "Core.Camera.FreeCamera"

local T = Core.Camera.FreeCamera.FreeCamera(0,0,-35)

c = T:getObjectType() -- nil reference
print(c .." --Type" )

and here is Camera.lua the base class

local _G = _G
module(...)



local M = _G.Class()
Camera = M

function M:__constructor(x,y,z) --This never gets called.
    --self.Active = false
    --self.x = x
    --self.y = y
    --self.z = z
    --self.ID = EngineManager:getCamera()
    print("InCameraInstance_-_-_-_-_-__-_--_-__-_-_-_--_-_-_-_-_--_-_-_--_--__-_---_--_---__-")
end

function M:getObjectType()
    return "camera"
end

And Finally Free Camera which attempts to inherit Camera.

local require = require
local _G = _G

module(...)

require "Core.Camera.Camera"

local M = _G.Class( _G.Core.Camera.Camera ) --Gross, lame might be the culprit
FreeCamera = M

function M:__constructor(x,y,z) ---WHOOPS, this does get called... the other one doesnt
self.Active = false
    self.x = x
    self.y = y
    self.z = z
    self.ID = _G.EngineManager:getCamera()
    --_G.print("got Id of:" .. self.ID)
    self:setCameraPosition(x, y, z, self.ID)
    _G.print("<<<Camera in lua>>>")
end

I’m running out of ideas. any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:23:00+00:00Added an answer on May 13, 2026 at 6:23 pm

    Instead of:

    local M = _G.Class( _G.Core.Camera.Camera )
    

    you need to have:

    local M = _G.Class( _G.Core.Camera.Camera.Camera )
    

    First Camera is the directory name, second is the module name, third is the class name.

    Edit: You can clean it up a bit like this:

    local CameraModule = require "Core.Camera.Camera"
    local M = _G.Class( CameraModule.Camera )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 368k
  • Answers 368k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer divs is a string, so divs.length would return the length… May 14, 2026 at 6:06 pm
  • Editorial Team
    Editorial Team added an answer IMO putting thousand of files in one directory isn't a… May 14, 2026 at 6:05 pm
  • Editorial Team
    Editorial Team added an answer The answer the interviewer is likely watching for is "what… May 14, 2026 at 6:05 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.