Exposing std::vector to Lua

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Exposing std::vector to Lua

Alexander Gladysh
Hi, all!

Suppose I have following (actually, legacy and hard-to-change)
construct (irrelevant details are hidden):

  class Item; // Registered to Luabind.

  typedef std::vector<Item> Items;

  class Holder
  {
  public:
    Items & GetItems() { return m_Items; }
    const Items & GetItems() const { return m_Items; }

    Holder(const Items & items)
      : m_Items(items)
    {
    }

  private:
    Items m_Items;
  };

I want to expose class Holder to Lua. What is the best way to do it?

I need all following features related to Items container on Lua side.

1. Construction of Holder class with pre-set Items collection.
2. Iteration in for loop.
3. Random read/write access to existing Items.
4. Addition of new Items at end of container (as vector::push_back does).

Of course, I can expose explicit methods to do all these, but I'd like
to have those features in Lua-way -- in syntax close as much as
possible to native Lua tables.

Thanks in advance,
Alexander.


_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Exposing std::vector to Lua

Korval
Make a wrapper class for Items and Holder. They would not deal directly with
std::vector, but instead expose Lua-appropriate functionality via existing
means.

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]On Behalf Of
Alexander Gladysh
Sent: Wednesday, June 21, 2006 5:02 AM
To: [hidden email]
Subject: [luabind] Exposing std::vector to Lua


Hi, all!

Suppose I have following (actually, legacy and hard-to-change)
construct (irrelevant details are hidden):

  class Item; // Registered to Luabind.

  typedef std::vector<Item> Items;

  class Holder
  {
  public:
    Items & GetItems() { return m_Items; }
    const Items & GetItems() const { return m_Items; }

    Holder(const Items & items)
      : m_Items(items)
    {
    }

  private:
    Items m_Items;
  };

I want to expose class Holder to Lua. What is the best way to do it?

I need all following features related to Items container on Lua side.

1. Construction of Holder class with pre-set Items collection.
2. Iteration in for loop.
3. Random read/write access to existing Items.
4. Addition of new Items at end of container (as vector::push_back does).

Of course, I can expose explicit methods to do all these, but I'd like
to have those features in Lua-way -- in syntax close as much as
possible to native Lua tables.

Thanks in advance,
Alexander.


_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user


All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Exposing std::vector to Lua

Alexander Gladysh
> Make a wrapper class for Items and Holder. They would not deal directly with
> std::vector, but instead expose Lua-appropriate functionality via existing
> means.

Can you please rephrase what you mean. I do not quite understand :(

Thanks,
Alexander.

All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user