supertux icon indicating copy to clipboard operation
supertux copied to clipboard

Revamp the scripting API

Open MatusGuy opened this issue 1 year ago • 4 comments

I've had an idea for a while now. Let's revamp the scripting api by using a library called simplesquirrel. With this we could practically replace miniswig, which just adds another thing to setup. Also it's a code generator. Code generator bad.

We could replace the functionality of ExposedObject by making the expose function explicitly expose the selected functions:

static void expose(ssq::VM& vm) {
  ssq::Class cls = vm.addClass("BadGuy", ssq::Class::Ctor<Foo(<arguments for badguy constructor>)>());

  // You can also use lambdas (or std::function) to define constructor
  // The function has to return pointer to the new instance
  //
  // vm.addClass("BadGuy", [](<arguments for badguy constructor>) -> BadGuy* {
  //     return new BadGuy(msg);
  // });

  cls.addFunc("kill_fall", &BadGuy::kill_fall);
  cls.addFunc("set_action", &BadGuy::set_action);

  cls.addVar("dir", &BadGuy::m_dir);
}

This is ripped from simplesquirrel's readme. The readme has really interesting stuff. I recommend you check it out. I also have an idea of being able to override the BadGuy class like if you were programming a badguy in C++ (but it's in squirrel).

Hopefully this will make it less tedious to add scripting features.

If no one wants to tackle this, I can do it after #2621 and #2485

MatusGuy avatar Jan 15 '24 22:01 MatusGuy

#650 #732

tobbi avatar Jan 15 '24 23:01 tobbi

Ye but sqrat sux

MatusGuy avatar Jan 16 '24 00:01 MatusGuy

SimpleSquirrel is abandoned, might not be a good idea unless it gets forked and maintained by the SuperTux team (probably not ideal?)

tulpenkiste avatar Jan 16 '24 16:01 tulpenkiste

I was thinking about forking, actually. At least it's more recent than sqrat

MatusGuy avatar Jan 16 '24 16:01 MatusGuy