cleolibrary / CLEO-Redux

Experimental JavaScript runtime for GTA 3D era games/GTA IV/Bully
https://re.cleo.li
Other
214 stars 20 forks source link

Add type label #73

Closed ghosty2004 closed 1 year ago

ghosty2004 commented 2 years ago

Hi, I just want to register some SA:MP natives in this cool JavaScript runtime and I need the label type to add in sa.json

Basically I have this native register:

{
  "id": "0B34",
  "name": "sampRegisterChatCommand",
  "num_params": 2,
  "input": [
    {
      "name": "cmd",
      "type": "string"
    },
    {
      "name": "func",
      "type": "label"
    }
  ]
}

And this function:

// method 1
native("sampRegisterChatCommand", "test", () => {
   log("Command /test called");
});

// method 2
function test() {
   log("Command /test called");
}
native("sampRegisterChatCommand", "test", test);

The problem is that not working with this label type

[ERROR] Unknown argument type function in command sampRegisterChatCommand
x87 commented 2 years ago

label type will never work in JS as it is something that has a meaning only in compiled CLEO scripts (.cs). JavaScript files have different structure. None of the existing CLEO commands that use label will work in JS. Once the support for callbacks is implemented (#28) those commands can be rewritten with CLEO Redux SDK to work with javascript functions instead.

x87 commented 1 year ago

https://github.com/cleolibrary/CLEO-Redux/issues/94#issuecomment-1585813060 for more detailed answer