-
Notifications
You must be signed in to change notification settings - Fork 22
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
Function as class member throws illegal signature
and crashes the game
#31
Comments
Hi @kindlich, Would it be possible to add an Proposed zs syntax: interface IInterfaceName {
IItemStack,
Type2,
Type3
} |
Hey there, I apologize for the late reply. var myTestFun as function(string)void = function(s as string) as void {print(s);};
myTestFun('Hello World');
function myAcceptFun(consumer as function(string)void) as void {
consumer('hello from inside myAcceptFun');
}
myAcceptFun(myTestFun);
myAcceptFun(function(s as string) as void {print('Another thing: ' ~ s);}); Would print
And zenClass myClass {
var consumer as function(string)void;
zenConstructor(consumer as function(string)void) {
this.consumer = consumer;
}
function acceptString(x as string) as void {
consumer(x);
}
}
myClass(function(x as string) as void {print('inside fun: ' ~ x);}).acceptString('abc'); Would print
|
That is extremely neat ! No problem for the long wait, this isn't exactly a core feature of zs/CrT (and almost out of scope). Though it is super nice that it's now possible. Thank you ! |
Hi @kindlich ,
I tried to define a custom ZenClass with a custom function as a member. Since functions can be used as globals, I expected them to be valid class members. However, my attempts throw a
Java.lang.ClassFormatError: Field "f" in class ZenClassCrafttweakerExecutor_Executor_0 has illegal signature "ZenClassCrafttweakerExecutor1"
and crash the whole game.As a side note, defining functions with no arguments and no return value doesn't seems to work, hence bizarre signatures in my script. I tried
function()void
,function()IAny
andfunction(void)void
, though I might have overlooked something.Expected behavior:
function are valid class members (if intended). If they should not be, trying to use them as class members should only crash the script, not the whole game.
Rationale:
Since ZenScript is intended as a scripting language, function class members may be out of scope. It would however provide great flexibility for repetitive processes and definitions. Rather than defining multiple classes that look very alike, it would be possible to use a single class and provide function members to its instances.
Also, it would allow to circumvent #26 using executor classes, which is what I was trying to do as a test. I'm trying to define a scheduling mechanism with functions being fired in proper order, at different game tweaking stages.
Versions:
Script used:
Click to expand
Crash StackTrace:
Click to expand
Thanks for looking into the issue and (potential) feature request !
EDIT: added minecraft's, forge's and CrT's versions
The text was updated successfully, but these errors were encountered: