skaarj1989 / entt-meets-sol2

Use EnTT in Lua with Sol2
Creative Commons Zero v1.0 Universal
47 stars 4 forks source link

Register runtime Lua components? #3

Open sigmareaver opened 4 days ago

sigmareaver commented 4 days ago

Does this library have that functionality? It wasn't clear to me from the readme, but I'm interested in doing something like this:

function newTransform(x_, y_, z_)
  local transform={
      x = x_;
      y = y_;
      z = z_;
      move = function(self, x_, y_, z_)
          self.x = x_;
          self.y = y_;
          self.z = z_;
      end;
      show = function(self)
          print("pos: ",self.x,", ",self.y,", ",self.z);
      end;
  }
  return transform;
end

function init()
  registry:register(newTransform(0, 0, 0));
end

Not exactly a perfect example, but hopefully it conveys my meaning.

skaarj1989 commented 4 days ago

No, you can't add a component whose type is defined in a lua script. Is it possible? how to do that? I don't know, sorry.

sigmareaver commented 4 days ago

I think it may be possible, by registering sol::table component class in C++, but one would have to devise a way of tracking the different Lua objects (component types). I will probably look into this eventually, unless someone beats me to it.

skaarj1989 commented 4 days ago

It's in EnTT TODO list, I'll keep my on that.

  • runtime types support for meta for types that aren't backed by C++ types