JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q59678F
  • License ISC

A lua interpreter for js

Package Exports

  • lua-interpreter

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lua-interpreter) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

LUA-INTERPRETER

Lua interpreter is a js interpreter that works in pair with the npm package luaparse or any package that outputs the same data

How to use ?

require("lua-interpreter")
interpret(you-ast-from-luaparse)

Other features

Custom methods : var methods = { print:{call:(arguments,scope)=>{ console.log(parseArguments(arguments,scope)) }} }

interpret(<code>,methods)

The method object contains a call function that will be called everytime the function is called and it takes 2 parameters : the arguments and the scope !

What is the scope ?

The scope is the collection of the variables that will be passed from functions to functions: in lua those can be referenced as local variables or iterators in for loops, basically it's just the variables that are only available in the block they have been defined

Functions to help you make custom built-in methods

This module contains various javascript functions that enables you to make functions that will be there by default when the script is being executed

Those are :

Parse argument

Parse argument will take an argument that you have passed in a function for example and return it's value because since values can change during run time luaparse doesn't tell the value directly and those functions return the value with the currect type

parseArgument(argument,scope) // Will parse the argument 
parseArguments(arguments,scope) // Will call parse argument for an array

Examples :

print:{call:(arguments,scope)=>{
    console.log(parseArguments(arguments,scope))
}}

Date:{call:(arguments,scope)=>{
    return {
        now : Date.now()
    }
}}

Parse expression

This is a big part of the parseArgument function, it parse any expression such as val * val , val == val .... and returns the value of this expression

Use : parseExpression(expression,scope)

Execute block

This is pretty self explanatory , it executes a given block

Use : executeBlock(block,scope)

A block can be for example a function call from luaparse