Last active
June 13, 2019 22:30
-
-
Save joseoliv/bd059a42a6c2facf55c584972a751cec to your computer and use it in GitHub Desktop.
createFieldIfAccessed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package metaobjectTest | |
@doc{* | |
Annotation 'createFieldIfAccessed' should be attached to a prototype. | |
It will simulates the existence of fields using a hash table. | |
If the prototype does not declare field 'iv' and 'self.iv' is used in the | |
prototype, it is replaced by a get or set in the hash table. The type of | |
'iv' will be considered 'Int' if its name starts with 'i', | |
'String' if it starts with 's', or 'Dyn' otherwise. | |
This is a demonstration metaobject | |
*} | |
@createFieldIfAccessed | |
object CreateFieldIfAccessed | |
func run { | |
self.iv = 0; | |
var Int var_iv = self.iv; | |
assert var_iv == 0; | |
self.str = "abc"; | |
var String var_str = self.str; | |
assert var_str == "abc"; | |
} | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment