# lua-interpreter

> A lua interpreter for js

Latest version **0.0.3** (published 2020-11-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install lua-interpreter
pnpm add lua-interpreter
yarn add lua-interpreter
bun add lua-interpreter
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2020-11-28 |
| First published | 2020-11-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sawcce |
| Maintainers | sawcce |
| Keywords | lua, luaparse, interpreter, fast, easy, lightweight |

## Links

- npm: https://www.npmjs.com/package/lua-interpreter
- Homepage: https://github.com/SauceArgente/lua-interpreter#readme
- npm.io page: https://npm.io/package/lua-interpreter

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2020-11-28
- 0.0.22 — 2020-11-28
- 0.0.21 — 2020-11-28
- 0.0.2 — 2020-11-28
- 0.0.142 — 2020-11-27
- 0.0.141 — 2020-11-27
- 0.0.14 — 2020-11-27
- 0.0.13 — 2020-11-27
- 0.0.12 — 2020-11-27
- 0.0.11 — 2020-11-26
- 0.0.1 — 2020-11-26

## 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)
    executeBlocks(blocks,scope) // Will do the same but for an array of blocks

A block can be for example a function call from luaparse

# Contribute to the project

Check out the github repo !

---
_Source: https://npm.io/package/lua-interpreter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
