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

  • SEARCH
  • Home
  • 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 6700003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:45:46+00:00 2026-05-26T06:45:46+00:00

Currently I have something in lua that is like OOP using tables. TCharacterController =

  • 0

Currently I have something in lua that is like OOP using tables.

TCharacterController = {}
TCharacterController.speed = 10.0
TCharacterController.axis = "x"

function TCharacterController:new(o)
    o = o or {}
    setmetatable(o, self)
    self.__index = self
    return o
end

function TCharacterController:update()
    --this is a function that is called by the C application
end

The concept is that I will create a child object

ScriptObj = TCharacterController:new()

for each script instance attached to an object in my application (this is for a game). So I have an entity layer and all of the entities will have the ability to have a ScriptObj attached to them. My idea is that the Script is actually a class and it is instantiated for each entity it is attached too.

My question is, how do I instantiate the instance of the TCharacterController using the C API?

  • 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-26T06:45:47+00:00Added an answer on May 26, 2026 at 6:45 am

    Since new is using the self reference syntatic sugar, you need to pass self as the first arg, the rest is just a function call of a table lookup:

    lua_getglobal(L, "TCharacterController"); /* get the table */
    lua_getfield(L, -1, "new");  /* get the function from the table */
    lua_insert(L, -2); /* move new up a position so self is the first arg */
    lua_pcall(L, 1, 1); /* call it, the returned table is left on the stack */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a table structure that looks something like this(some details omitted): ColumnName
I currently have service classes that look something like this public class UserService :
I currently have something like this <p class=test></p> <script type=text/javascript> $(document).ready(function() { $(.test).html(hey); });
We currently have an ant task that contains something similar to the following: <filelist
I currently have my PHP class variables set up like this: class someThing {
Currently, I have something like: public partial class Form1 : Form { delegate void
I currently have something like this for my route table. Is there a nicer
I currently have something of the form abc=`find ~/$folder .. etc I'd like to
I currently have something like this: UPDATE table1 SET column1 = REPLACE(column1, 'abc', 'abc1')
I currently have something like this: $(.jtable tbody td).not(.DeleteLicense).hover( How can I use delegate

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.