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

Some questions and suggestions about data model #145

Closed
cloudwu opened this issue Nov 7, 2020 · 2 comments
Closed

Some questions and suggestions about data model #145

cloudwu opened this issue Nov 7, 2020 · 2 comments

Comments

@cloudwu
Copy link
Contributor

cloudwu commented Nov 7, 2020

I'm trying to write a lua binding for data model these days, and I have some questions.

  1. DataModel::BindFunc can only bind a function Function<void(Variant&)> , it's very limit for dynamic language because the function in lua (or other script language) is data rather than a function code address. I think Function<void(Variant&,void *)> would be more useful .
// add `ud` for `get_func` and `set_func`, we can bind lua_State and other states into func.
bool DataModel::BindFunc(const String& name, DataGetFunc get_func, DataSetFunc set_func, void *ud); 
  1. I need use DataModel::BindVariable to bind the variable in lua . I can't use DataModelConstructor::Bind , it can only bind a memory address but the variable in lua is not. I suggest to add BindVariable into the class DataModelConstructor, and I can write a VariableDefinition for lua variables.

  2. About the DataModel::Update. Why not update all the data models automatically in Context::Update ? Or adding a Context::UpdateDataModels would be useful. it can reduce the complexity of management in lua bindings. For example, if I create a new data model in <script> , the framework doesn't need to know which data model should be update before Context::Update.

@mikke89
Copy link
Owner

mikke89 commented Nov 7, 2020

Appreciate the feedback! I'll try to answer as best I can.

  1. The Get/Set functions are just aliases for std::function so you can for example capture the lua_State in a lambda function.

  2. Oh, so if I understand you correctly, you want to bind a DataVariable with a custom VariableDefinition. I think this makes sense for advanced use cases, we can certainly add something like that.

  3. Makes me happy you say this, because I made these exact changes in the data_binding branch. Here, DataModel::Update is gone, and Context::Update and Context::LoadDocument will take care of updating it. The only downside is that dirty variables will be cleared whenever we call one of these functions. I'm not sure how or if we should deal with this, or whether it is a case of just documenting it properly and let users deal with it.

I'm very interested to see how you end up integrating data bindings into the Lua plugin. Perhaps you'd like to contribute upstream when you have something working well? :)

@cloudwu
Copy link
Contributor Author

cloudwu commented Nov 8, 2020

Thanks.

The data binding I wrote is for my own lua plugin, it has a little different structure from the offical version . The main motivation of making another version of lua plugin is that the offical version is too complex in C++ code. I would like a very thin and flex wrapper in C++ side, and put most things into lua side (something like livespan management, adding methmethod, etc).

But I wrote a simplified version for offical lua plugin today. (see #146) Much remains to be done, but I wish it can give you some inspiration.

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

2 participants