-
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic function calling. #6713
base: feature/script-reflection
Are you sure you want to change the base?
Dynamic function calling. #6713
Conversation
Co-authored-by: Patrick Miller <apickledwalrus@gmail.com>
What about #6254? |
also see #6254 (comment). i have to be honest - i'm not really a fan of reflective capabilities in vanilla skript |
I, too, am not a big fan. |
Sorry if im blanking right now, but why would you even need this in the first place? you could just... run the function? i dont see any point for this atleast in my eyes |
I am not against the idea in general mainly for the fact that it provides a way to execute functions in a more natural way I haven't yet reviewed the implementation so I can't really comment on that yet |
I would guess it would be used to do something like command /kit <number>:
trigger:
run function named "giveKit%arg-1%" But i dont see it as that useful personally |
Personally hate this example a more fexible one would be custom enchantments and
replace name with enchantment name each time and call it from there, so you have basically a wrapper method now |
I’m going to be flat out honest here, and this is just how I view things. |
i agree that dynamic function calling is a useful feature, but i think it should be a simple |
I really don't think this, as a concept, is that hard to grasp for an average user. Whether or not it belongs in Skript or reflect is another debate, but I really see no problem with the complexity side of things. In my eyes its the same kind of thing as the math functions - if they don't understand, then it's probably not for them, and they can just call the function normally. |
I thought I would take the opportunity to clean up a few questions about functions. What does dynamic calling do?
Dynamic (or indirect) calling means running something when you don't explicitly know [what/where] it is. This doesn't need to be linked to reflection (in fact C doesn't really have a concept of reflection, but still has call-by-pointer functions). It means you can prepare a function call in advance, store it (or even pass it somewhere else) and then invoke it when you need to. function completeQuest(user: player, onSuccess: function):
# check quest completion logic
send "You've finished the quest!" to {_user}
if {_onSuccess} exists:
run {_onSuccess} with arguments {_user} In this case, it also allows you to call a function by its name (e.g.
It's been a staple of programming since the COBOL and FORTRAN days.
Click here for some examples :) |
To throw in my two cents, I’d generally caution against becoming overprotective of Skript’s simplicity to the point that we reject powerful and useful features. I agree that this isn’t even very complex, but even if it was, I don’t see how a language with a goal of being beginner friendly necessitates literally every aspect of it being beginner friendly. The language can both be beginner friendly and have complex elements as long as those complexities aren’t required of beginners. I’d even argue including an intentional amount of extra opt-in complexity is a great way to help beginners deepen their skills in a low-commitment way. I’d also argue this only comes off as reflection by necessity. Half of the huge gain here is the ability to pass callbacks, which essentially every other language supports and is in itself not reflexive in many languages. A JavaScript example can also be done as follows: class Foo {
bar(…) {…}
}
let v = new Foo();
someOtherFunctionAcceptingACallback(v.bar); The ability to pass callbacks is a key developer tool that we’ve always been missing. Shove it in skript-reflect if you want, but it feels like a key part of a language so I’d argue Skript core makes more sense as its home. |
My opinion has been swayed by @Moderocky's comments on the benefits of first-order functions, I think this is a good idea. |
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just some clerical stuff, nice work!
import ch.njol.skript.variables.Variables; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.eclipse.jdt.annotation.Nullable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong nulllable
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
/** | ||
* This file is part of Skript. | ||
* | ||
* Skript is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Skript is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Skript. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Copyright Peter Güttinger, SkriptLang team and contributors | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kill it
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
Co-authored-by: sovdee <10354869+sovdeeth@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests failing and unresolved changes
Additions
New types
Obtain function references by name (& source)
Run function references & get results
Little examples
Infrastructure
Road-map of future plans
I'm setting down a bit of API here for future Skript features/addons to use,
especially ones that want to run tasks.
I have a few ideas about what I would like to do with this, but nothing finalised yet.
Target Minecraft Versions: any
Requirements: none
Related Issues: fixes #1265, fixes #5838, requires #6702