[Ohrrpgce] [ohrrpgce/ohrrpgce] Named (keyword) arguments in HamsterSpeak (#1156)

Ralph Versteegen notifications at github.com
Sun Aug 23 01:56:24 PDT 2020


I love the ability to specify arguments either by position or by name in Python and miss it in HS (and FreeBASIC). Since `=` is currently only used for declaring default arguments in HS, we could use it to pass arguments by name in HS to scripts and builtin commands:
```
set timer (0, 40, timer:default, timer:default, 4)
# equivalent to
set timer (0, count = 40, string = 4)
```

(We could even have the equivalent of `*args, **kwargs` in python, collecting extra arguments, though that's a separate request.)

Now, this is actually not easy to implement for dynamic callable objects like virtual methods if HS has to be translated to another language like Lua or Squirrel which doesn't have keyword arguments, but it can be implemented by storing metadata about the script/command arg names and translating to position args at runtime (runtime matching is unavoidable anyway). E.g. in Squirrel,
``damage callback(damage, BLUNT, attacker = enemy) ``
could become
```damage_callback.acall(translate_kwargs(damage_callback._arginfo, [damage, BLUNT], {attacker = enemy}))```
Or else it could just be disallowed when the specific script/command being called isn't known at compile-time.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/ohrrpgce/ohrrpgce/issues/1156
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.motherhamster.org/pipermail/ohrrpgce-motherhamster.org/attachments/20200823/013770b6/attachment-0001.html>


More information about the Ohrrpgce mailing list