-
Notifications
You must be signed in to change notification settings - Fork 18
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
Local multi-dimensional arrays #90
Comments
There's a comment in preprocessor_plugins.py, at line 522 that says "Multidimensional arrays are only allowed in the init callback" :/ |
It also won't compile if you import a script that has an "on_init_[something]" function and inline that function in "on init". Should work there really as code compiled that way results in anything in "on_init_[something]" being inlined in "on init" as described in Nil's original documentation. |
If your in-line doesn’t work, it’s because there’s a part of code inside it that doesn’t work in the init callback. The easiest example is if you in-line a function that uses “call [function]” inside of it. |
imported_script.ksp: |
You can not declare multi dim arrays in functions, which is why it doesn’t work. It doesn’t matter if you only use it inside of a function you happen to use in-line. The function has to be understood by the compiler first before it can be used in-line. It can’t be understood by the compiler if it doesn’t follow legally what a function can do. For this purpose, you simply just use a macro instead, which has no restrictions as the purpose is in-line text replacement. |
Functions starting with "on_init" behave differently to normal functions. It doesn't work, but it should because the array would be compiled into on init. |
There's nothing in the compiler to suggest the existence of this feature nor can I find anything in any Nils documentation suggesting that he did this besides a small note that if you write "on_init" in front of your function name, it will treat variable declarations as global. Even that, however, I can not find any actual code that does what he states. If you want init callback text replacements, you only need to use a macro. It's very easy and much more powerful. |
Multi-dim arrays were an appended feature created after Nils was working on the compiler, and so whoever created it did not treat it the same way as the rest of the code compilation process handles variables and arrays. That's why it is more limited than normal variables and arrays, since it is a "preprocessor" meaning it is checked for legal syntax before any functions are expanded. |
I've used the "on_init" thing for ages, it definitely works. Without it it won't compile. However, I'll try turning them into macros instead though I'm sure I had a problem with that when there were macros inside the imported function, can't test at the moment. I had no idea whether it was going to be an easy fix or a major pain so thought I'd mention it. Anyway, thanks a lot for your help. |
This wouldn't compile. "Syntax error" is returned. This happens regardless of the type of function (with return value, with parameters etc.). It happens even if the function is not called anywhere in the script.
The text was updated successfully, but these errors were encountered: