heroiclabs / nakama-defold

Defold client for Nakama server.
https://heroiclabs.com
Apache License 2.0
74 stars 12 forks source link

allow skipping optional arguments #46

Closed SamsTheGreatest closed 2 years ago

CLAassistant commented 2 years ago

CLA assistant check
All committers have signed the CLA.

SamsTheGreatest commented 2 years ago

This is generated code. Changes should be made to the code generator template. More info about the code generator can be found here: https://github.com/heroiclabs/nakama-defold/tree/master/codegen

Crazy stuff!

britzl commented 2 years ago

What we need is to change this:

https://github.com/heroiclabs/nakama-defold/blob/master/codegen/realtime.py#L203-L204

We want to check if a value is of the correct type or nil. Example:

assert(_G.type(some_string_var) == 'string' or some_string_var == nil)

So the relevant lines of the code generator should be changed to:

    for prop in props:
        lua = lua + "   assert(_G.type(%s) == '%s' or %s == nil)\n" % (prop["name"], prop["type"], prop["name"])
SamsTheGreatest commented 2 years ago

@britzl I would guess this shall only happen for args[4:] as the first 3 are essential? And only for this specific function right... So there shall be some function checks additionaly?

SamsTheGreatest commented 2 years ago

Oh it's in python? Thank god...

britzl commented 2 years ago

I would guess this shall only happen for args[4:] as the first 3 are essential? And only for this specific function right...

I would assume that there are other functions which also have optional arguments. We either do it for all functions and all arguments or none at all. How can we know which arguments that are optional if the API specification doesn't state it?

SamsTheGreatest commented 2 years ago

@britzl thats exactly what we discussed in the issue with missing docs... I guess if doing it for all of them would be a quick fix, but then if user doesnt give any parameters at all, lua will not throw any errors, only server will - could be a little more tricky to debug...

britzl commented 2 years ago

but then if user doesnt give any parameters at all, lua will not throw any errors, only server will

Sure, but what is the likelihood of that happening? You may also give the wrong values in which case the server will also return an error.

SamsTheGreatest commented 2 years ago

@britzl alright the argument actually makes a lot of sense. Just wish we had docs to refer to.. Lets go for the change.

britzl commented 2 years ago

Just wish we had docs to refer to..

Keep in mind that all of the clients use a very similar API. You should be able to refer to any of the other clients if something is missing from the Defold docs.

https://heroiclabs.com/docs/nakama/concepts/multiplayer/matchmaker/

Also, while I do recognise that it is not very beginner friendly, but you can also look at the source code itself. Here's the MatchmakerAdd message and what each field means:

https://github.com/heroiclabs/nakama-common/blob/master/rtapi/realtime.proto#L365-L379

britzl commented 2 years ago

Duplicate of https://github.com/heroiclabs/nakama-defold/pull/47