-
Notifications
You must be signed in to change notification settings - Fork 0
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
Custom Classes proposal #37
Comments
Conditional Methodsmethod could be conditional:
gets compiled as
Design ChoicesIf the method is a template that simply gets inserted in-place of a call statement (see Design choices in the first post) you can not put anything except conditional opcodes in a method to be able to use it in the conditional expression. i.e. this would not be allowed:
|
Returning ResultsIt's unclear how to work with returning a value from the methods, i.e consider:
how to represent Design Choices
always having to pass a variable to store a result into can be tedious for simple cases like:
one would want to simply have
then
this adds a lot of unusual syntax into the language.
|
Powerful! The question is: will the compiler pick up the declared classes if they are described in another file and were included via the I also wanted to ask: will it be possible to add constants to a class? Like this
|
@wmysterio static class variables could be a nice feature! Will keep that in mind. |
Class instances should support inline declaration similar to primitive types:
|
todo: update this proposal after #263 |
2024 Draft
|
Class Syntax
Here is the proposal to add a new syntax for defining custom classes in scripts. They may eventually become a replacement for static classes in the classes.db.
Let's take a look at an example:
Here we defined a class named
Actor
that has one methodputInCar
in.putInCar
method has one parametercar
. Then we declared a variable0@
of the typeActor
and finally called methodputInCar
on that class instance.Important Notes
[email protected]($car)
no code was produced in this script.self
that represents the class instance the method is called on. in this case it is the variable0@
[email protected]($car)
gets compiled into036A: put_actor 0@ in_car $car
Design Choices
when there is a method call statement the compiler takes the method body and replaces the statement with the entire body. it means the method could have many instructions and possibly even labels and they will be put in place of the call statement. in this sense class method are more templates than functions as in the other languages.
this however does not prevent local variables from being altered inside the method body. it means there is no separate scope created when the class method is called and if you, for example, change the variable 0@ in the class method it will be a side-effect for the caller:
There are a few possible choices to this dilemma:
gosub
they could alter local scope as well)The text was updated successfully, but these errors were encountered: