1. Go to this page and download the library: Download m3m0r7/rubyvm-on-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
m3m0r7 / rubyvm-on-php example snippets
nstantiate RubyVM class
$rubyVM = new \RubyVM\VM\Core\Runtime\RubyVM(
new \RubyVM\VM\Core\Runtime\Option(
reader: new \RubyVM\Stream\BinaryStreamReader(
streamHandler: new \RubyVM\Stream\FileStreamHandler(
// Specify to want you to load YARV file
__DIR__ . '/HelloWorld.yarv',
),
),
// Choose Logger
logger: new \Psr\Log\NullLogger(),
),
);
// Disassemble instruction sequence binary formatted and get executor
$executor = $rubyVM->disassemble();
// You can choose to run ruby version if you needed
// $executor = $rubyVM->disassemble(
// useVersion: \RubyVM\RubyVersion::VERSION_3_2,
// );
// Execute disassembled instruction sequence
$executor->execute();
nstantiate RubyVM class
$rubyVM = new \RubyVM\VM\Core\Runtime\RubyVM(
new \RubyVM\VM\Core\Runtime\Option(
reader: new \RubyVM\Stream\BinaryStreamReader(
streamHandler: new \RubyVM\Stream\FileStreamHandler(
// Specify to want you to load YARV file
__DIR__ . '/test.yarv',
),
),
// Choose Logger
logger: new \Psr\Log\NullLogger(),
),
);
// Disassemble instruction sequence binary formatted and get executor
$executor = $rubyVM->disassemble();
// Execute disassembled instruction sequence
$executed = $executor->execute();
// Call Ruby method as below code.
// In this case, you did define method name is `callFromPHP`.
$executed->context()->callFromPHP();
$executed->context()->callFromPHP('Hello World! Here is passed an argument from PHP!')
// You can display processed an INSN table when adding below code
$executor->context()->option()->debugger()->showExecutedOperations();
// Use breakpoint debugger with option
$rubyVM = new \RubyVM\VM\Core\Runtime\RubyVM(
new \RubyVM\VM\Core\Runtime\Option(
// excluded...
debugger: new \RubyVM\VM\Core\Runtime\Executor\Debugger\StepByStepDebugger(),
),
);
$ composer
./vendor/bin/php-cs-fixer fix --allow-risky=yes
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.