forked from kanaka/mal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vbs: shorten env.vbs, avoid recursion
- Loading branch information
1 parent
e317748
commit efcd38a
Showing
1 changed file
with
16 additions
and
47 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,35 @@ | ||
Option Explicit | ||
|
||
Function NewEnv(objOuter) | ||
Dim varRet | ||
Set varRet = New Environment | ||
Set varRet.Self = varRet | ||
Set varRet.Outer = objOuter | ||
Set NewEnv = varRet | ||
NewEnv = New Environment | ||
NewEnv.Outer = objOuter | ||
End Function | ||
|
||
Class Environment | ||
Private objOuter, objSelf | ||
Private objBinds | ||
Private objBinds, objOuter | ||
|
||
Private Sub Class_Initialize() | ||
Set objBinds = CreateObject("Scripting.Dictionary") | ||
Set objOuter = Nothing | ||
Set objSelf = Nothing | ||
' objSelf Is Nothing | ||
End Sub | ||
|
||
Public Property Set Outer(objEnv) | ||
Set objOuter = objEnv | ||
End Property | ||
|
||
Public Property Get Outer() | ||
Set Outer = objOuter | ||
End Property | ||
|
||
Public Property Set Self(objEnv) | ||
Set objSelf = objEnv | ||
End Property | ||
|
||
Public Sub Add(varKey, varValue) | ||
Set objBinds.Item(varKey) = varValue | ||
End Sub | ||
|
||
Public Function Find(varKey) | ||
Dim varRet | ||
If objBinds.Exists(varKey) Then | ||
Set varRet = objSelf | ||
Else | ||
If TypeName(objOuter) <> "Nothing" Then | ||
Set varRet = objOuter.Find(varKey) | ||
Else | ||
Set varRet = Nothing | ||
End If | ||
End If | ||
|
||
Set Find = varRet | ||
End Function | ||
|
||
Public Function [Get](varKey) | ||
Dim objEnv, varRet | ||
Set objEnv = Find(varKey) | ||
If objEnv Is objSelf Then | ||
Set varRet = objBinds(varKey) | ||
Else | ||
If TypeName(objEnv) <> "Nothing" Then | ||
Set varRet = objEnv.Get(varKey) | ||
Else | ||
Set varRet = Nothing | ||
End If | ||
End If | ||
|
||
Set [Get] = varRet | ||
Dim objEnv = Me | ||
Do Until objEnv.objBinds.Exists(varKey) | ||
objEnv = objEnv.objOuter | ||
If TypeName(objEnv) = "Nothing" Then | ||
' [Get] Is Nothing | ||
Exit Function | ||
End If | ||
Loop | ||
Set [Get] = objEnv.objBinds(varKey) | ||
End Function | ||
End Class | ||
End Class |