irule 0.1-universal-dotnet

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE.txt +21 -0
  2. data/README.rst +32 -0
  3. data/lib/irule.cs +81 -0
  4. data/lib/irule.dll +0 -0
  5. data/lib/tcl.rb +19 -0
  6. metadata +61 -0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2010 Ian Dees
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.rst ADDED
@@ -0,0 +1,32 @@
1
+ =====
2
+ Irule
3
+ =====
4
+
5
+ Irule, the .I.ron.RU.by tc.L. .E.xtension, is a Ruby library that
6
+ provides a minimal wrapper around the Tcl programming language for
7
+ IronRuby_. It mimics the ``load_from_file`` and ``eval`` methods from
8
+ its more full-featured cousin, the tcl_ Ruby library.
9
+
10
+ Prerequisites
11
+ -------------
12
+ #. Tcl 8.4.
13
+ #. Mono or .NET.
14
+
15
+ Installation
16
+ ------------
17
+
18
+ ``igem install irule``, or just put ``tcl.rb`` and ``irule.dll``
19
+ somewhere in your ``LOAD_PATH``.
20
+
21
+ Usage
22
+ -----
23
+
24
+ Sample code::
25
+
26
+ require 'tcl'
27
+
28
+ tcl = Tcl::Interp.load_from_file 'some.tcl'
29
+ result = tcl.eval 'someTclCode'
30
+
31
+ .. _IronRuby: http://ironruby.net
32
+ .. _tcl: http://rubygems.org/gems/tcl
data/lib/irule.cs ADDED
@@ -0,0 +1,81 @@
1
+ // The code is new, but the idea is from http://wiki.tcl.tk/9563
2
+
3
+ using System;
4
+ using System.Runtime.InteropServices;
5
+
6
+ namespace Irule
7
+ {
8
+ public class TclInterp : IDisposable
9
+ {
10
+ [DllImport("tcl8.4")]
11
+ protected static extern IntPtr Tcl_CreateInterp();
12
+
13
+ [DllImport("tcl8.4")]
14
+ protected static extern int Tcl_Init(IntPtr interp);
15
+
16
+ [DllImport("tcl8.4")]
17
+ protected static extern int Tcl_Eval(IntPtr interp, string script);
18
+
19
+ [DllImport("tcl8.4")]
20
+ protected static extern IntPtr Tcl_GetStringResult(IntPtr interp);
21
+
22
+ [DllImport("tcl8.4")]
23
+ protected static extern void Tcl_DeleteInterp(IntPtr interp);
24
+
25
+ [DllImport("tcl8.4")]
26
+ protected static extern void Tcl_Finalize();
27
+
28
+ protected const int TCL_ERROR = 1;
29
+
30
+ private IntPtr interp;
31
+ private bool disposed;
32
+
33
+ public TclInterp()
34
+ {
35
+ interp = Tcl_CreateInterp();
36
+ Tcl_Init(interp);
37
+
38
+ disposed = false;
39
+ }
40
+
41
+ public void Dispose()
42
+ {
43
+ Dispose(true);
44
+ GC.SuppressFinalize(this);
45
+ }
46
+
47
+ protected virtual void Dispose(bool disposing)
48
+ {
49
+ if (!disposed)
50
+ {
51
+ if (disposing && interp != IntPtr.Zero)
52
+ {
53
+ Tcl_DeleteInterp(interp);
54
+ Tcl_Finalize();
55
+ }
56
+
57
+ interp = IntPtr.Zero;
58
+ disposed = true;
59
+ }
60
+ }
61
+
62
+ public string Eval(string text)
63
+ {
64
+ if (disposed)
65
+ {
66
+ throw new ObjectDisposedException("Attempt to use disposed Tcl interpreter");
67
+ }
68
+
69
+ var status = Tcl_Eval(interp, text);
70
+ var raw = Tcl_GetStringResult(interp);
71
+ var result = Marshal.PtrToStringAnsi(raw);
72
+
73
+ if (TCL_ERROR == status)
74
+ {
75
+ throw new Exception("Tcl interpreter returned an error: " + result);
76
+ }
77
+
78
+ return result;
79
+ }
80
+ }
81
+ }
data/lib/irule.dll ADDED
Binary file
data/lib/tcl.rb ADDED
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + '/irule.dll'
2
+
3
+ module Tcl
4
+ class Interp
5
+ def initialize
6
+ @interp = Irule::TclInterp.new
7
+ end
8
+
9
+ def eval(text)
10
+ @interp.eval text
11
+ end
12
+
13
+ def self.load_from_file(file)
14
+ interp = Interp.new
15
+ interp.eval IO.read(file)
16
+ interp
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: irule
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: universal-dotnet
6
+ authors:
7
+ - Ian Dees
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-05-13 00:00:00 -07:00
12
+ default_executable:
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ type: :development
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: Provides an tiny subset of the tcl gem for IronRuby
25
+ email:
26
+ - undees@gmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - lib/irule.cs
32
+ - lib/irule.dll
33
+ - lib/tcl.rb
34
+ - LICENSE.txt
35
+ - README.rst
36
+ has_rdoc: true
37
+ homepage: http://github.com/undees/irule
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.3.5
54
+ version:
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: .I.ron.RU.by tc.L. .E.xtension
61
+ test_files: []