Skip to content

guiled/Hoathis-Lua

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hoathis\Lua

This library proposes an interpreter and a compiler for the Lua language in PHP, based on Hoa\Compiler.

Quick usage

This is a work in progress, but here is a toy example. The Input.lua file:

a = 39
b = '3'
a, b = b, a + 1
z = 42

function f ( x, y )

    var_dump(x, y)

    function g ( h )
        var_dump(h)
    end

    z = y / 2

    g(z)
end

f(a, b)

And the interpreter:

<?php

require '/usr/local/lib/Hoa/Core/Core.php';

from('Hoa')
-> import('File.Read')
-> import('Compiler.Llk.~');

from('Hoathis')
-> import('Lua.Visitor.Interpreter');

$compiler = \Hoa\Compiler\Llk::load(
    new \Hoa\File\Read('hoa://Library/Lua/Grammar.pp')
);
$input    = (new \Hoa\File\Read('Input.lua'))->readAll();
$ast      = $compiler->parse($input);
$visitor  = new \Hoathis\Lua\Visitor\Interpreter();

$visitor->visit($ast);

/**
 * Will output:
 *     string(1) "3"
 *     int(40)
 *     int(20)
 */

About

The Hoathis\Lua library: a Lua interpreter and compiler based on Hoa\Compiler.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 91.4%
  • Puppet 8.6%