Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to create getters and setters for sub-tables #1659

Open
dheerajshenoy opened this issue Dec 28, 2024 · 0 comments
Open

Question: How to create getters and setters for sub-tables #1659

dheerajshenoy opened this issue Dec 28, 2024 · 0 comments

Comments

@dheerajshenoy
Copy link

Thanks for this great library!

Sorry if the question doesn't make any sense, I just don't know how to explain it in a sentence. Let's say I have a table table with the sub-tables ui and opt. I want to have getter/setter for members of opt e.g: table.opt.terminal = "value" and print(table.opt.terminal). I have defined the sol::state in a class and all the lua API definitions should reside in this class.

How can I get the following behavior

class Table {

public:
   void LuaAPI() noexcept;

private:
   sol::state lua;
};

void Table::LuaAPI() noexcept {
  sol::table table = lua.create_named["table"]
  table.new_usertype<Table>("table");
  
  table["opt"] = this;
  
  table["opt"]["terminal"] = sol::property(&Table::Getter, &Table::Setter);
  
  table["ui"]... // UI table with members
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant