Git Product home page Git Product logo

lua-in-js's Introduction

Joined Github 7 years ago.

Since then I pushed 2441 commits, opened 215 issues, submitted 368 pull requests, received 919 stars across 11 personal projects and contributed to 8 public repositories.

Most used languages across my projects:

TypeScript Rust Julia JavaScript HTML Lua CSS Other

Generated using teoxoy/profile-readme-stats

lua-in-js's People

Contributors

keith2018 avatar lbguilherme avatar teoxoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

lua-in-js's Issues

Task lib

I can't seem to find any task lib.

For example you can't use the function Wait() or task.Wait()

For loops

lua for loops dont seem to compile into js for loops

Browser version

Will there be a browser version, just like with Starlight?

Set lua variable to function that was loaded by javascript?

In my Javascript script code I'm loading a class with all of its functions and properties, then returning loading that library. How could I set a lua variable when creating that class. Example:
Javascript:

function newClass(){
    const example = new Class()

    const name = example.name
    const id = example.id

    function changeName(newName) {
        return example.name = newName
    }

    const lib = new luainjs.Table({
        name,
        id,
        changeName
    })

    return luaEnv.loadLib("Example", lib)
}

luaEnv.loadLib("Instance", new luainjs.Table({
    newClass
}))

Then in lua I am trying to do:

    local ex = Instance.newClass()
    print(ex.name,ex.id)

Without doing

    local ex = Instance.newClass()
    print(Example.name,Example.id)

Logical operators evaluate left-hand side twice

For context, I am using lua-in-js for unit testing redis scripts in node. It mostly works great for this, thanks! However I noticed that mocks were getting called multiple times in some scripts when I didn't think they should be.

Turns out that some logical operators appear to evaluate the LHS twice. This makes sense as it looks as transpilation for them is implemented via simple string substitution:

return `(!__lua.bool(${left})?${left}:${right})`

This should probably be updated to assign the result of left to a local variable first, assuming you have some mechanism to maintain hygiene and avoid unintended shadowing? I'm no Lua expert but I think it is not supposed to eval LHS twice. Please correct me if I'm understanding something wrong, I really just glanced over and made a lot of assumptions!

Error in math.random

  • math.random():
    Generates a random floating-point number in the range [0, 1).
  • math.random(upper):
    Generates a random integer in the range [1, upper].
  • math.random(lower, upper):
    Generates a random integer in the range [lower, upper].
function random(min, max) {
    if (min === undefined && max === undefined)
        return getRandom();
    const firstArg = coerceArgToNumber(min, 'random', 1);
    const MIN = max === undefined ? firstArg : 1;
    const MAX = max === undefined ? coerceArgToNumber(max, 'random', 2) : firstArg;
    if (MIN > MAX)
        throw new Error("bad argument #2 to 'random' (interval is empty)");
    return Math.floor(getRandom() * (MAX - MIN + 1) + MIN);
}

should be:

const MIN = max !== undefined ? firstArg : 1;
const MAX = max !== undefined ? coerceArgToNumber(max, 'random', 2) : firstArg;

When requiring lua files, lua-in-js cannot find the file?

I'm trying to require another file and whenever I try to require it, my console errors and tells me that the module is not found. The path the file is located in is: ../node_modules/lua-hill/modules/globals. I call:

local mod = require("../node_modules/lua-hill/modules/globals")

and then my console spits out: message: "Module '../node_modules/lua-hill/modules/globals.lua' not found!"

How to add a global variable to the env?

First thanks for making this lib, can't really guess how I would make something like this myself.

I'm trying to add a global variable which is a table but I'm having no luck doing it.

Lua Code Example:

Trace = lua.Trace
Warn = lua.Warn

MersenneTwister = { Random=math.random, Seed=math.randomseed }

PLAYER_1 = "PlayerNumber_P1"
PLAYER_2 = "PlayerNumber_P2"
NUM_PLAYERS = #PlayerNumber

The problem I'm having is with trying to add PlayerNumber as the file I'm executing expects it to be a defined global. It was trivial to add lua.Trace and lua.Warn with the documentation provided at the readme, I simply did was such bellow

const luaAdditional = new luainjs.Table({
	Trace: (msg) => {
		console.log(msg)
	},
	Warn: (msg) => {		
		console.warn(msg)
	}
})
luaEnv.loadLib('lua', luaAdditional)

However, I can't find exactly how I could add a global table, I've tried adding it to the global variable directly such as

const globalEnv = new luainjs.Table({
	PlayerNumber: new luainjs.Table({ '1': 'PlayerNumber_P1' })
})
luaEnv.loadLib('_G', globalEnv)

And it did not work, I tried looking at what the table gets transformed into lua-side and also tried this:

const globalEnv = new luainjs.Table({
	keys: [1, 2],
	values: ['PlayerNumber_P1', 'PlayerNumber_P2']
})
luaEnv.loadLib('PlayerNumber', globalEnv)

But whatever I added as argument to the Table method would always be inside srtValues.

Given my failed attempts, how could I add a PlayerNumber table as a global to the file I parse?

Here's the result I'm trying to reach:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.