Skip to content

How to return other foreign class obj from a foreign class ? #1182

Open
@tommego

Description

@tommego

I'm Writing small game engine with wren binding support(love wren language very mutch, binding raylib to wren...)
My wren.inc codes:

foreign class Color{
    foreign r
    foreign r=(val)
    foreign g
    foreign g=(val)
    foreign b
    foreign b=(val)
    foreign a
    foreign a=(val)
}

foreign class Object {
    foreign color // but how to implement this form c/c++ using wrenSetSlotNewForeign? this function I tested it's classSlot just must be 0, and only could create new instance object to class Object 
    foreign color=(val) // currently I can implement this from c/c++
}

My cpp codes:(for getter/setter)

void wrenSetObjectColor(WrenVM* vm) {
    ((Object*)wrenGetSlotForeign(vm, 0))->color =  *((Color*)wrenGetSlotForeign(vm, 1));
}

// but how to implement?
void wrenGetObjectColor(WrenVM* vm) {
   auto inst =  ((Object*)wrenGetSlotForeign(vm, 0));
   wrenSetSlotNewForeign(vm, 0, ?, sizeof(Color));
   auto tmp = ((Color*)wrenGetSlotForeign(vm, 0));
   memcpy(tmp, &inst->color, sizeof(Color));
}
// this not work...

I had implement Json.hpp Bingding for wren Map value, my codes post to this issue.
Json.hpp binding to wren Map codes & test

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions