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 4626764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:28:05+00:00 2026-05-22T03:28:05+00:00

I have a Lua class like below. I am using json to serialize the

  • 0

I have a Lua class like below. I am using json to serialize the object and put it in a key value store. I am able to serialize the object and put it in the key value store successfully but i am not able to call any methods of the object after i retrieve the object from the key value store. I understand the json module skips the methods while encoding and my object does not have methods after decoding.

Is there a way to append methods to the class after i decode the object from json to lua ? some thing similar to function pointers in C language.

local class_name = "user_object";
user_object = {};  --user class 


function user_object.new (mobile, password, uid)

        local self = {};
        self.mobile = mobile;
        self.uid    = uid; -- generate a uid which is a running number.
        self.password = password;
        self.messages_sent = 0;
        self.put_request_count = 0;
        self.get_request_count = 0;
        self.last_time_active = "";
        self.get_tickets = {};
        self.put_tickets = {};
        self.group_message_stream = {};
        self.group_ownerships = {}; -- group names which he is owner of 
        self.group_memberships = {}; -- group names  which he is member of 
        self.sent_poke_count = 0;
        self.sent_poke_stream = {};
        self.recv_poke_count = 0;
        self.recv_poke_stream = {};

        function self:add_put_ticket(ticketid)
                table.insert(self.put_tickets, ticketid);
                self:incr_put_count();
                self:save();
                return;
        end 

        function self:add_get_ticket(ticketid)
                table.insert(self.get_tickets, ticketid);
                self:incr_get_count();
                self:save();
                return;
        end
  • 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-22T03:28:06+00:00Added an answer on May 22, 2026 at 3:28 am

    Function in Lua are first class objects, you can store a function in any variable. The line

    function self:add_put_ticket(ticketid)
    

    is equivalent to

    self.add_put_ticket = function (self, ticketid)
    

    From there, it should be obvious what to do: define your desired methods where they are accessible and assign them to the appropriate fields after deserialization

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with large numbers that I can't have rounded off. Using Lua's standard
I was thinking about making something like Linq for Lua, and I have a
I'm using Lua inside a C application, and I have two tables. I want
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
class data is like this: struct Base_data { public: Base_data(){ protocolname = Base; }
I have implemented OOP in my lua environment but it doesnt seem to be
Currently I know how to have C++ objects instantiated and passed around in Lua
I have been looking for tutorials demonstrating how to share a C++ object with
I have a small app that uses Lua linked as dll (not static). I

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.