Skip to content

Commit

Permalink
Call Groovy from VB.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
PyjaErskell committed Dec 9, 2019
1 parent df65325 commit 1793c04
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ECHO OFF
SETLOCAL
MKDIR "%~DP0ecu"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\vbc.exe /target:winexe "/out:%~DP0ecu\SToa.exe" "%~DP0src\SToa.vb"
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//---------------------------------------------------------------
// Global
//---------------------------------------------------------------

gf_cls = { x_cls_nm -> Class .forName (x_cls_nm) } // find class from string

gp_make_globals = { -> this.binding.variables .each { x2_key, x2_value -> if ( ! x2_key .startsWith ('_') ) { Object.metaClass."$x2_key" = x2_value } } }
gp_make_globals ()

//---------------------------------------------------------------
// Your Source
//---------------------------------------------------------------

sf_hello = { x_str, x_no -> "Hello ${ x_str * x_no } !!!" }
sf_sum = { long ... x_args -> x_args*.value .sum () }
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#---------------------------------------------------------------
# Global
#---------------------------------------------------------------

$GC_FOSA = File::ALT_SEPARATOR || File::SEPARATOR # (fo)lder (s)ep(a)rator
$GC_PASA = File::PATH_SEPARATOR # (pa)th (s)ep(a)rator

$gf_pj = -> ( * x_args ) { x_args .join $GC_FOSA } # (p)ath (j)oin
$gf_bn = -> (x_fn) { File .basename x_fn } # (b)ase (n)ame
$gf_id = -> (x_it) { File .directory? x_it } # (i)s (d)irectory
$gf_pn = -> ( x_it, x_chedk_id = false ) { ( x_chedk_id and ( $gf_id .(x_it) ) ) ? (x_it) : ( File .dirname x_it ) } # (p)ath (n)ame
$gf_on = -> ( x_it, x_chedk_id = false ) { $gf_bn .( $gf_pn .( x_it, x_chedk_id ) ) } # f(o)lder (n)ame

$GC_OLIM_PN = $gf_pn .($GC_MILO_PN)
$GC_OLIM_NM = $gf_on .( $GC_OLIM_PN, true )

$GC_TONO_HM = $GC_MILO_PN
$GC_TONO_NM = $gf_on .( $GC_TONO_HM, true )

$gf_sf = -> ( * x_args ) { sprintf *x_args } # (s)tring (f)ormat

$GC_KAPA_HM = $gf_pj .( 'C:', 'ProgramData', 'Bichon Frise', 'Kapa' )

$GC_JAVA_HM = $gf_pj .( $GC_KAPA_HM, '19.11.01', 'Vindue', 'x64', 'Amazon', 'Corretto', '8.232.09.1' )
ENV['JAVA_HOME'] = $GC_JAVA_HM

require 'rjb'

-> () {
pu_jars = [
$gf_pj .( $GC_KAPA_HM, '19.01.22', 'Cumuni', 'Groovy', '2.5.8', 'indy', 'groovy-2.5.8-indy.jar' ),
$gf_pj .( $GC_KAPA_HM, '19.01.22', 'Cumuni', 'Groovy', '2.5.8', 'indy', 'groovy-jsr223-2.5.8-indy.jar' ),
] .join $GC_PASA
Rjb::load pu_jars, ['-Dfile.encoding=UTF-8']
} .()

$ju_g = ( Rjb::import 'javax.script.ScriptEngineManager' ) .new .getEngineByName ('Groovy')
$jf_ge = -> (x_str) { $ju_g .eval x_str } # ge = (g)roovy (e)val
$jf_gf = -> ( x_nm, * x_args ) { $ju_g .invokeFunction x_nm.to_s, x_args } # gf = (g)roovy (f)unction

$jf_ge .( File .read $gf_pj .( $GC_MILO_PN, 'src', 'SToa.groovy' ) )

$jf_cls = -> (x_cls_nm) { $jf_gf .( 'gf_cls', x_cls_nm ) }

$CjSystem = $jf_cls .('java.lang.System')
$CjString = $jf_cls .('java.lang.String')

$jf_sf = -> ( x_format, * x_args ) { $CjString .format x_format, x_args }

$GC_JAVA_VR = $CjSystem .getProperty 'java.version'
$GC_GROOVY_VR = $jf_ge .('GroovySystem.version') .toString

#---------------------------------------------------------------
# Your Source
#---------------------------------------------------------------

$sf_hello = -> ( x_str, x_no ) { $jf_gf .( 'sf_hello', x_str, x_no ) .toString }
$sf_sum = -> ( * x_args ) { $jf_gf .( 'sf_sum', *x_args ) .longValue }
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
Imports Glabol
Imports System.Drawing
Imports System.Windows.Forms

'---------------------------------------------------------------
' Global
'---------------------------------------------------------------

Public Class Glabol
Public Shared Dim gu_r = CreateObject ("ruby.object.2.4")
Shared Sub New ()
gf_er ("" & _
"-> (x_milo_pn) {" & vbCrLf & _
" pu_src_pn = x_milo_pn + '\src'" & vbCrLf & _
" $LOAD_PATH .unshift pu_src_pn unless $LOAD_PATH .include? pu_src_pn" & vbCrLf & _
" $GC_MILO_PN = x_milo_pn" & vbCrLf & _
" require 'SToa'" & vbCrLf & _
"}" _
) .call ( IO.Directory .GetParent ( IO.Path .GetDirectoryName (Reflection.Assembly.GetExecutingAssembly.Location) ) .ToString () )
End Sub
Public Shared Function gf_er ( x_code As String ) ' (er)ubyize
Return gu_r .erubyize (x_code)
End Function
End Class

'---------------------------------------------------------------
' Your Source
'---------------------------------------------------------------

Public Class WMain
Inherits Form
Dim wu_lbx As New ListBox
Public Sub New ()
Me.Size = New Size ( 550, 200 )
Me .CenterToScreen ()
wu_lbx.Dock = DockStyle.Fill
AddHandler Me.Shown, AddressOf wn_shown
Me.Controls .Add (wu_lbx)
End Sub
Private Sub wn_shown ( x_sender As Object, x_eas As EventArgs)
Me.Text = String .Format ( "{0} : {1}", gf_er ("$GC_OLIM_NM") .to_s, gf_er ("$GC_TONO_NM") .to_s )
With wu_lbx .Items
.Add ( ".NET version => " & Environment.Version .ToString () )
.Add ( "Ruby version => " & gf_er ("RUBY_VERSION") .to_s )
.Add ( "Java version => " & gf_er ("$GC_JAVA_VR") .to_s )
.Add ( "Groovy version => " & gf_er ("$GC_GROOVY_VR") .to_s )
.Add ( "Ruby sprintf ""%1$*2$s %2$d %1$s"", ""Hello"", 8 => " & gf_er ("$gf_sf") .call ( "%1$*2$s %2$d %1$s", "Hello", 8 ) )
.Add ( "Ruby sprintf ""%1$*2$s %2$d %1$s"", ""Korea (한글)"", 20 => " & gf_er ("$gf_sf") .call ( "%1$*2$s %2$d %1$s", "Korea (한글)", 20 ) )
.Add ( "Java string format ""Hello %s (%,d) !!!"", ""Java"", 3141592 => " & gf_er ("$jf_sf") .call ( "Hello %s (%,d) !!!", "Java", 3141592 ) )
.Add ( "Java string format ""Hello %s (%,d) !!!"", ""Korea (자바)"", 3141592 => " & gf_er ("$jf_sf") .call ( "Hello %s (%,d) !!!", "Korea (자바)", 3141592 ) )
.Add ( "Groovy hello (English) => " & gf_er ("$sf_hello") .call ( "Groovy-", 5 ) )
.Add ( "Groovy hello (Korea) => " & gf_er ("$sf_hello") .call ( "그루비-", 5 ) )
.Add ( "Groovy sum of numbers => " & String .Format ( "{0:n0}", gf_er ("$sf_sum") .call ( 700000000, 12, 49, 15, 51, 94, 21, 63 ) ) )
End With
End Sub
Public Shared Sub Main()
Application .Run ( New WMain () )
End Sub
End Class

0 comments on commit 1793c04

Please sign in to comment.