SFTtech / nyan

Typesafe hierarchical key-value database with inheritance and dynamic patching :smiley_cat:
Other
207 stars 29 forks source link

Python API #64

Open TheJJ opened 4 years ago

TheJJ commented 4 years ago

nyan needs a Python API in order to be used from Python code, like the openage-converter. Best to use Cython. It can be done with the traditional Cython approach by just wrapping the C++-code with pyx and pxd files.

Using openage's Python interface is probably overkill (no need to call back and forth easily, translate exceptions from Py to C++, ...).

coco875 commented 11 months ago

It will be interesting if you can make some metaclass like (also this syntax is if function in nyan are the same declaration then python etc)

Health:
  _hp = 0
  _shield = 10 // the shield don't regen
  function __get__():
    return _hp

  funciton __set__(value):
    _hp = value

  function __add__(value):
    _hp += value

  function __sub__(value):
    if _shield < 0:
      _hp -= value
    else:
      _shield -= value

Strider(Unit):
    hp = Health
    hp = 10
    hp += 10 // so now hp == 20
    hp -= 10 // hp still 20 because shield
    hp -= 5 // hp == 15 because shield is below 0
    animation = "./assets/strider.ani"
TheJJ commented 11 months ago

please open a separate issue for this feature request :) then we can discuss it independently of the python api.