Git Product home page Git Product logo

Comments (5)

husanpao avatar husanpao commented on September 24, 2024

但是用了折中的方法可以解决了,就是先将struct 转为new_table然后再加入map,vector等容器既可以用

from luakit.

xiyoo0812 avatar xiyoo0812 commented on September 24, 2024

但是用了折中的方法可以解决了,就是先将struct 转为new_table然后再加入map,vector等容器既可以用

C++传递 基于自定义struct的容器给lua吗?这种建议先将struct注册成class就可以在容器中使用

from luakit.

husanpao avatar husanpao commented on September 24, 2024

但是用了折中的方法可以解决了,就是先将struct 转为new_table然后再加入map,vector等容器既可以用

C++传递 基于自定义struct的容器给lua吗?这种建议先将struct注册成class就可以在容器中使用

好的,待会使用看一下。谢谢您的解答

from luakit.

husanpao avatar husanpao commented on September 24, 2024

这种注册是不行的,或许是我的写法错了

c++:

struct Event {
    Label weight;
    float hold;
    int event;
    int left;
    int right;
    int top;
    int bottom;
};
struct Label {
    string name;
    bool render;
    string text;
    float threshold;
    bool flag;
};

 kit_state.new_class<Label>(
            "name", &Label::name,
            "render", &Label::render,
            "text", &Label::text,
            "threshold", &Label::threshold,
            "flag", &Label::flag
    );
    kit_state.new_class<Event>(
            "weight", &Event::weight,
            "hold", &Event::hold,
            "event", &Event::event,
            "left", &Event::left,
            "right", &Event::right,
            "top", &Event::top,
            "bottom", &Event::bottom
    );
    Label l = {"name", false, "text", 1, false};
    Event e = {l, 1, 1, 1, 1, 1, 1};
    kit_state.set("testEvent", e);
    kit_state.table_call("Plugin", "Test");


lua:
function Plugin:Test()
    print(testEvent.event)
    print(testEvent.weight.name)
end

这种使用是ok的

c++:

class LabelClass {
public:
    string name;
    bool render;
    string text;
    float threshold;
    bool flag;
};

class EventClass {
public:
    LabelClass *weight;
    float hold;
    int event;
    int left;
    int right;
    int top;
    int bottom;
};

kit_state.new_class<LabelClass>(
            "name", &LabelClass::name,
            "render", &LabelClass::render,
            "text", &LabelClass::text,
            "threshold", &LabelClass::threshold,
            "flag", &LabelClass::flag
    );
    kit_state.new_class<EventClass>(
            "weight", &EventClass::weight,
            "hold", &EventClass::hold,
            "event", &EventClass::event,
            "left", &EventClass::left,
            "right", &EventClass::right,
            "top", &EventClass::top,
            "bottom", &EventClass::bottom
    );
    LabelClass *l = new LabelClass();
    l->name = "name";
    l->threshold = 1;
    l->render = false;
    l->text = "text";
    l->flag = true;
    auto e = new EventClass();
    e->hold = 1;
    e->bottom = 1;
    e->event = 1;
    e->weight = l;
    e->top = 1;
    e->left = 1;
    e->right = 1;
    kit_state.set("testEvent", e);
    kit_state.table_call("Plugin", "Test");

lua:
function Plugin:Test()
    print(testEvent.event)
    print(testEvent.weight.name)
end

这种注册是可以使用的

from luakit.

xiyoo0812 avatar xiyoo0812 commented on September 24, 2024

这种注册是不行的,或许是我的写法错了

c++:

struct Event {
    Label weight;
    float hold;
    int event;
    int left;
    int right;
    int top;
    int bottom;
};
struct Label {
    string name;
    bool render;
    string text;
    float threshold;
    bool flag;
};

 kit_state.new_class<Label>(
            "name", &Label::name,
            "render", &Label::render,
            "text", &Label::text,
            "threshold", &Label::threshold,
            "flag", &Label::flag
    );
    kit_state.new_class<Event>(
            "weight", &Event::weight,
            "hold", &Event::hold,
            "event", &Event::event,
            "left", &Event::left,
            "right", &Event::right,
            "top", &Event::top,
            "bottom", &Event::bottom
    );
    Label l = {"name", false, "text", 1, false};
    Event e = {l, 1, 1, 1, 1, 1, 1};
    kit_state.set("testEvent", e);
    kit_state.table_call("Plugin", "Test");


lua:
function Plugin:Test()
    print(testEvent.event)
    print(testEvent.weight.name)
end

这种使用是ok的

c++:

class LabelClass {
public:
    string name;
    bool render;
    string text;
    float threshold;
    bool flag;
};

class EventClass {
public:
    LabelClass *weight;
    float hold;
    int event;
    int left;
    int right;
    int top;
    int bottom;
};

kit_state.new_class<LabelClass>(
            "name", &LabelClass::name,
            "render", &LabelClass::render,
            "text", &LabelClass::text,
            "threshold", &LabelClass::threshold,
            "flag", &LabelClass::flag
    );
    kit_state.new_class<EventClass>(
            "weight", &EventClass::weight,
            "hold", &EventClass::hold,
            "event", &EventClass::event,
            "left", &EventClass::left,
            "right", &EventClass::right,
            "top", &EventClass::top,
            "bottom", &EventClass::bottom
    );
    LabelClass *l = new LabelClass();
    l->name = "name";
    l->threshold = 1;
    l->render = false;
    l->text = "text";
    l->flag = true;
    auto e = new EventClass();
    e->hold = 1;
    e->bottom = 1;
    e->event = 1;
    e->weight = l;
    e->top = 1;
    e->left = 1;
    e->right = 1;
    kit_state.set("testEvent", e);
    kit_state.table_call("Plugin", "Test");

lua:
function Plugin:Test()
    print(testEvent.event)
    print(testEvent.weight.name)
end

这种注册是可以使用的

可能是有些成员判定的模板问题,我抽时间测试下

from luakit.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.