jerryscript-project / jerryscript

Ultra-lightweight JavaScript engine for the Internet of Things.
https://jerryscript.net
Apache License 2.0
6.89k stars 669 forks source link

[Question] How to implement class and inherits from C side? #5029

Closed dxjia closed 1 year ago

dxjia commented 1 year ago

Hello, I'm trying to implement inheriting classes from C side, can someone tell me how to do this? any ideas will be appreciated. For details, one SuperClassB inhirts from SuperClassA, both of them are expected to be explored to ES world from C side, and one ChildClass can be implemented from ES side then.

// how to implement following two classes from C side?
class SuperClassA {
  static testA() {
    // do something 
  }
}

class SuperClassB {
  static testB() {
    // do something 
  }
}
zherczeg commented 1 year ago

In general there is no simple way to do this. JerryScript supports native C function callbacks. You can build a system on top of it (something auto-generates code for classes).