Skip to content

Commit

Permalink
Upgraded Roo to 2.1.4
Browse files Browse the repository at this point in the history
Adds support for the `type` getter and the `responds_to?()` method on ALL objects.
  • Loading branch information
gkjpettet committed Jul 17, 2018
1 parent 1b7f3d1 commit 3c65c3e
Show file tree
Hide file tree
Showing 16 changed files with 136 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Roo.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Protected Module Roo
#tag EndMethod


#tag Constant, Name = VERSION_BUG, Type = Double, Dynamic = False, Default = \"3", Scope = Public
#tag Constant, Name = VERSION_BUG, Type = Double, Dynamic = False, Default = \"4", Scope = Public
#tag EndConstant

#tag Constant, Name = VERSION_MAJOR, Type = Double, Dynamic = False, Default = \"2", Scope = Public
Expand Down
87 changes: 87 additions & 0 deletions src/Roo/GenericObjectRespondsToMethod.xojo_code
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#tag Class
Protected Class GenericObjectRespondsToMethod
Implements Invokable, Textable
#tag Method, Flags = &h0
Function Arity() As Variant
return 1
End Function
#tag EndMethod

#tag Method, Flags = &h0
Sub Constructor(parent as RooInstance)
self.parent = parent

End Sub
#tag EndMethod

#tag Method, Flags = &h0
Function Invoke(interpreter as Interpreter, arguments() as Variant, where as Token) As Variant
#pragma Unused interpreter

' Make sure a Text argument is passed to the method.
if not arguments(0) isA TextObject then
raise new RuntimeError(where, "The responds_to?(what) method expects a text parameter. " + _
"Instead got " + VariantType(arguments(0)) + ".")
end if

dim what as String = TextObject(arguments(0)).value

if parent.klass.FindMethod(parent, what) = Nil then
return new Roo.Objects.BooleanObject(False)
else
return new Roo.Objects.BooleanObject(True)
end if
End Function
#tag EndMethod

#tag Method, Flags = &h0
Function ToText() As String
' Part of the Textable interface.

return "<function responds_to?>"
End Function
#tag EndMethod


#tag Property, Flags = &h0
parent As Roo.RooInstance
#tag EndProperty


#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass
11 changes: 11 additions & 0 deletions src/Roo/Lookup.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Protected Module Lookup
arrayObjGetters.Value("reverse!") = True
arrayObjGetters.Value("shuffle!") = True
arrayObjGetters.Value("to_text") = True
arrayObjGetters.Value("type") = True
arrayObjGetters.Value("unique") = True
arrayObjGetters.Value("unique!") = True
End Sub
Expand Down Expand Up @@ -97,6 +98,7 @@ Protected Module Lookup
booleanObjGetters.Value("nothing?") = True
booleanObjGetters.Value("number?") = True
booleanObjGetters.Value("to_text") = True
booleanObjGetters.Value("type") = True
End Sub
#tag EndMethod

Expand Down Expand Up @@ -124,6 +126,7 @@ Protected Module Lookup
fileObjGetters.Value("path") = True
fileObjGetters.Value("readable?") = True
fileObjGetters.Value("to_text") = True
fileObjGetters.Value("type") = True
fileObjGetters.Value("writeable?") = True
End Sub
#tag EndMethod
Expand All @@ -150,6 +153,7 @@ Protected Module Lookup
hashObjGetters.Value("nothing?") = True
hashObjGetters.Value("number?") = True
hashObjGetters.Value("to_text") = True
hashObjGetters.Value("type") = True
hashObjGetters.Value("values") = True
End Sub
#tag EndMethod
Expand Down Expand Up @@ -188,6 +192,7 @@ Protected Module Lookup
matchInfoObjGetters.Value("number?") = True
matchInfoObjGetters.Value("start") = True
matchInfoObjGetters.Value("to_text") = True
matchInfoObjGetters.Value("type") = True
matchInfoObjGetters.Value("value") = True
End Sub
#tag EndMethod
Expand All @@ -209,6 +214,7 @@ Protected Module Lookup
nothingObjGetters.Value("nothing?") = True
nothingObjGetters.Value("number?") = True
nothingObjGetters.Value("to_text") = True
nothingObjGetters.Value("type") = True
End Sub
#tag EndMethod

Expand Down Expand Up @@ -246,6 +252,7 @@ Protected Module Lookup
numberObjGetters.Value("to_degrees") = True
numberObjGetters.Value("to_radians") = True
numberObjGetters.Value("to_text") = True
numberObjGetters.Value("type") = True
End Sub
#tag EndMethod

Expand All @@ -266,6 +273,7 @@ Protected Module Lookup
regexObjGetters.Value("nothing?") = True
regexObjGetters.Value("number?") = True
regexObjGetters.Value("to_text") = True
regexObjGetters.Value("type") = True
End Sub
#tag EndMethod

Expand All @@ -280,6 +288,7 @@ Protected Module Lookup
regexMatchObjGetters.Value("number?") = True
regexMatchObjGetters.Value("start") = True
regexMatchObjGetters.Value("to_text") = True
regexMatchObjGetters.Value("type") = True
regexMatchObjGetters.Value("value") = True
End Sub
#tag EndMethod
Expand Down Expand Up @@ -317,6 +326,7 @@ Protected Module Lookup
regexResultObjGetters.Value("nothing?") = True
regexResultObjGetters.Value("number?") = True
regexResultObjGetters.Value("to_text") = True
regexResultObjGetters.Value("type") = True
End Sub
#tag EndMethod

Expand Down Expand Up @@ -355,6 +365,7 @@ Protected Module Lookup
textObjGetters.Value("swapcase") = True
textObjGetters.Value("swapcase!") = True
textObjGetters.Value("to_text") = True
textObjGetters.Value("type") = True
textObjGetters.Value("uppercase") = True
textObjGetters.Value("uppercase!") = True
End Sub
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/ArrayObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ Inherits RooInstance
return self
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("Array")
case "unique"
return DoUnique(False)
case "unique!"
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/BooleanObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Inherits RooInstance
return new BooleanObject(False)
case "to_text"
return new TextObject(if(value, "True", "False"))
case "type"
return new TextObject("Boolean")
end select
end if

Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/FileObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ Inherits RooClass
else
return new TextObject(self.file.NativePath)
end if
case "type"
return new TextObject("File")
case "writeable?"
return DoWriteable()
end select
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/HashObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ Inherits RooInstance
return new BooleanObject(False)
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("Hash")
case "values"
return DoValues()
end select
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/MatchInfoObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Inherits RooInstance
return new NumberObject(self.start)
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("MatchInfo")
case "value"
return new TextObject(self.value)
end select
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/NothingObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Inherits RooInstance
return new BooleanObject(False)
case "to_text"
return new TextObject("Nothing")
case "type"
return new TextObject("Nothing")
end select
end if

Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/NumberObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Inherits RooInstance
return new NumberObject(value / 57.295779513)
case "to_text"
return new TextObject(self.ToText())
case "type"
return new TextObject("Number")
end select
end if

Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/RegexMatchObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Inherits RooInstance
return new NumberObject(info.start)
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("RegexMatch")
case "value"
return new TextObject(info.value)
end select
Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/RegexObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Inherits RooInstance
return new BooleanObject(False)
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("Regex")
end select
end if

Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/RegexResultObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Inherits RooInstance
return new BooleanObject(False)
case "to_text"
return new TextObject(self.ToText)
case "type"
return new TextObject("RegexResult")
end select
end if

Expand Down
2 changes: 2 additions & 0 deletions src/Roo/Objects/TextObject.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ Inherits RooInstance
return DoSwapCase(True)
case "to_text"
return new TextObject(value)
case "type"
return new TextObject("Text")
case "uppercase"
return new TextObject(value.Uppercase)
case "uppercase!"
Expand Down
13 changes: 12 additions & 1 deletion src/Roo/RooInstance.xojo_code
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Implements Textable
#tag EndMethod

#tag Method, Flags = &h0
Function Get(name as Token) As Variant
Function Get(name as Roo.Token) As Variant
' Return the requested property value if this instance has a property with the requested name.
if fields.HasKey(name.lexeme) then return fields.Value(name.lexeme)

Expand All @@ -26,6 +26,17 @@ Implements Textable
return self.klass.Get(name)
end if

' Handle the generic object methods `type` and `responds_to?`.
if StrComp(name.lexeme, "responds_to?", 0) = 0 then
return new GenericObjectRespondsToMethod(self)
elseif StrComp(name.lexeme, "type", 0) = 0 then
if self.klass <> Nil then
return new TextObject(self.klass.name)
else
return new TextObject(self.ToText)
end if
end if

' When looking up a property on an instance, if we don’t find a matching field, we look for a
' method with that name on the instance’s class. If found, we return that.
dim method as RooFunction = self.klass.FindMethod(self, name.lexeme)
Expand Down
5 changes: 3 additions & 2 deletions src/roo.xojo_project
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,12 @@ Class=Input;Roo/Native/Functions/Input.xojo_code;&h000000000CAB9FFF;&h0000000030
Class=Print;Roo/Native/Functions/Print.xojo_code;&h00000000349567FF;&h000000003091FFFF;false
Class=File;Roo/Native/Functions/File.xojo_code;&h00000000699AB7FF;&h000000003091FFFF;false
Class=CustomModule;Roo/CustomModule.xojo_code;&h000000003A0A5FFF;&h00000000529317FF;false
Class=GenericObjectRespondsToMethod;Roo/GenericObjectRespondsToMethod.xojo_code;&h000000001432DFFF;&h00000000529317FF;false
MajorVersion=2
MinorVersion=1
SubVersion=3
SubVersion=4
NonRelease=0
Release=0
Release=3
InfoVersion=
LongVersion=
ShortVersion=
Expand Down

0 comments on commit 3c65c3e

Please sign in to comment.