Index: src/ironruby/Ruby.csproj
===================================================================
--- src/ironruby/Ruby.csproj (revision 101)
+++ src/ironruby/Ruby.csproj (working copy)
@@ -10,10 +10,14 @@
Properties
Ruby
IronRuby
-
-
-
-
+
+
+
+
+
+
+
+
2.0
OnOutputUpdated
@@ -25,9 +29,11 @@
TRACE;DEBUG
prompt
4
-
+
+
..\..\..\MSSharedLibKey.snk
-
+
+
true
@@ -37,9 +43,11 @@
TRACE
prompt
4
-
+
+
..\..\..\MSSharedLibKey.snk
-
+
+
true
@@ -49,9 +57,11 @@
AnyCPU
prompt
true
-
+
+
..\..\..\SilverlightKey.snk
-
+
+
true
..\..\..\Utilities\Silverlight\x86ret\
@@ -62,9 +72,11 @@
pdbonly
AnyCPU
prompt
-
+
+
..\..\..\SilverlightKey.snk
-
+
+
true
..\..\..\Utilities\Silverlight\x86ret\
@@ -119,6 +131,7 @@
+
@@ -258,12 +271,12 @@
-
+
{2AE75F5A-CD1F-4925-9647-AF4D1C282FB4}
Microsoft.Scripting.Core
False
-
+
{EB66B766-6354-4208-A3D4-AACBDCB5C3B3}
Microsoft.Scripting
Index: src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs
===================================================================
--- src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs (revision 0)
+++ src/ironruby/Runtime/Globals/KCodeGlobalVariableInfo.cs (revision 0)
@@ -0,0 +1,64 @@
+/* ****************************************************************************
+ *
+ * Copyright (c) Microsoft Corporation.
+ *
+ * This source code is subject to terms and conditions of the Microsoft Public License. A
+ * copy of the license can be found in the License.html file at the root of this distribution. If
+ * you cannot locate the Microsoft Public License, please send an email to
+ * ironruby@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
+ * by the terms of the Microsoft Public License.
+ *
+ * You must not remove this notice, or any other, from this software.
+ *
+ *
+ * ***************************************************************************/
+
+using Microsoft.Scripting;
+
+using Ruby.Builtins;
+
+namespace Ruby.Runtime {
+ internal sealed class KCodeGlobalVariableInfo : GlobalVariable {
+ public readonly MutableString NONE = new MutableString("NONE");
+ public readonly MutableString UTF8 = new MutableString("UTF8");
+ public readonly MutableString SJIS = new MutableString("SJIS");
+ public readonly MutableString EUC = new MutableString("EUC");
+
+ private MutableString _value;
+
+ public KCodeGlobalVariableInfo() {
+ _value = NONE;
+ }
+
+ public override object GetValue(RubyExecutionContext /*!*/ context, RubyScope scope) {
+ return _value;
+ }
+
+ public override void SetValue(RubyExecutionContext /*!*/ context, RubyScope scope, SymbolId name, object value) {
+ string lang = value as MutableString;
+
+ if ((lang != null) && (lang.Length > 0)) {
+ switch (lang[0]) {
+ case 'E':
+ case 'e':
+ _value = EUC;
+ break;
+ case 'S':
+ case 's':
+ _value = SJIS;
+ break;
+ case 'U':
+ case 'u':
+ _value = UTF8;
+ break;
+ case 'N':
+ case 'n':
+ case 'A':
+ case 'a':
+ _value = NONE;
+ break;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Index: src/ironruby/Runtime/RubyExecutionContext.cs
===================================================================
--- src/ironruby/Runtime/RubyExecutionContext.cs (revision 101)
+++ src/ironruby/Runtime/RubyExecutionContext.cs (working copy)
@@ -269,7 +269,6 @@
// $0
// $?
- // $-K
DefineGlobalVariableNoLock(SymbolTable.StringToId("stdin"), new GlobalVariableInfo(StandardInput));
DefineGlobalVariableNoLock(SymbolTable.StringToId("stdout"), Runtime.GlobalVariables.OutputStream);
@@ -290,6 +289,11 @@
DefineGlobalVariableNoLock(SymbolTable.StringToId("DEBUG"), debug);
DefineGlobalVariableNoLock(SymbolTable.StringToId("-d"), debug);
+ KCodeGlobalVariableInfo kcode = new KCodeGlobalVariableInfo();
+
+ DefineGlobalVariableNoLock(SymbolTable.StringToId("KCODE"), kcode);
+ DefineGlobalVariableNoLock(SymbolTable.StringToId("-K"), kcode);
+
#if !SILVERLIGHT
DefineGlobalVariableNoLock(Symbols.CurrentProcessId, new ReadOnlyGlobalVariableInfo(Process.GetCurrentProcess().Id));
#endif
Index: tests/ironruby/Runtime/Global/test_kcode.rb
===================================================================
--- tests/ironruby/Runtime/Global/test_kcode.rb (revision 0)
+++ tests/ironruby/Runtime/Global/test_kcode.rb (revision 0)
@@ -0,0 +1,19 @@
+require '../../util/assert.rb'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'SJIS'
+
+assert_equal($KCODE, 'SJIS')
+assert_equal($-K, 'SJIS')
+
+$KCODE = 'NONE'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'BAD'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
Index: tests/ironruby/Runtime/Global/test_kcode.rb
===================================================================
--- tests/ironruby/Runtime/Global/test_kcode.rb (revision 0)
+++ tests/ironruby/Runtime/Global/test_kcode.rb (revision 0)
@@ -0,0 +1,19 @@
+require '../../util/assert.rb'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'SJIS'
+
+assert_equal($KCODE, 'SJIS')
+assert_equal($-K, 'SJIS')
+
+$KCODE = 'NONE'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')
+
+$KCODE = 'BAD'
+
+assert_equal($KCODE, 'NONE')
+assert_equal($-K, 'NONE')