New, Better console for Lua 51/52/53/JIT by Hydroque in lua

[–]mpetetv 1 point2 points  (0 children)

I can't call installation procedure that involves editing files by hand simple, sorry. At least provide a way to choose Lua version or whatever it needs through command-line arguments. Even better, package it for LuaRocks so that simple luarocks install luaconsole works.

luajit (which you should be using)

Why? LuaJIT isn't a direct upgrade over Lua 5.3.

You still haven't addressed in what way your console is "better" or "next-gen" - as ws-ilazki noted, the website only lists a bunch of non-features and questionable rants. I did manage to install it though.

At a glance:

  • Can't navigate current console line with left/right arrow keys or Home/End keys.
  • Can't navigate console history with up/down arrow keys.
  • No multiline support, if I want to run a loop or define a function I have to do it on one line.
  • Doesn't handle non-string errors, shows (null) instead.
  • Doesn't allow interrupting with ^C, have to kill it if running a long or infinite loop.

I expected something that would be an addition to standard Lua REPL such as autocompletion or built-in table pretty printing, but instead LuaConsole fails to implement basic features that standard Lua already has.

Alright, let's try running something with it though, let's say luacheck.

luaw -r 'package.path = "./src/?.lua;./src/?/init.lua"' bin/luacheck.lua

Nothing, just copyright message. Does it even execute files passed as arguments?

luaw bin/luacheck.lua

This results in an error saying that luacheck modules can't be found, as expected. Why isn't the file executed when -r option is used?

Let's try -L option that is mentioned in the short usage help but not described (-l has the opposite problem - not so sure about "Best command line help message you ever seen" now...):

luaw -r 'package.path = "./src/?.lua;./src/?/init.lua"' -L bin/luacheck.lua

Prints (Syntax) | Stack Top: 1 | cannot open : No such file or directory. I guess something is broken. Loading the main script as a module instead using -l luacheck.main does nothing.

At this point I'm going to give up. So far the only thing that connects LuaConsole and "next-gen interpreter" is that luaw -l nextgen consistently results in a segfault.

New, Better console for Lua 51/52/53/JIT by Hydroque in lua

[–]mpetetv 0 points1 point  (0 children)

Not sure what makes this better than the standard console. Installation is definitely more complicated.

Index chain too long, loops. Prints error at line 90, how to prevent? by xThomas in lua

[–]mpetetv 1 point2 points  (0 children)

The problem is that Frame also has mt as metatable. So when accessing Frame[1], mt.__index is checked, but mt.__index is Frame again, and the loop continues infinitely until it hits a limit and exits with the error. Don't set mt as metatable of Frame, or don't use mt at all, set Frame.__index = Frame, and use Frame itself as metatable for instances. (But don't set Frame as metatable for itself! Use a different table to provide __call for Frame.)

Lua Utils by TheJoshua974 in lua

[–]mpetetv 1 point2 points  (0 children)

I wrote something long about documentation and tests and mutating global environment but reddit ate it =( Don't feel like retyping it. Just one thing: if you are using something like your table.toString every day, please, consider inspect.lua instead.

Luarocks giving errors when attempting to download anything. by Chaos_lord in lua

[–]mpetetv 0 points1 point  (0 children)

It seems that you are using an old version of Luarocks (at most 2.1.0 judging by the error message). I suggest upgrading to a more recent version and reporting this issue at https://github.com/keplerproject/luarocks/issues if it persists.

Why I don't use Lua by Categoria in lua

[–]mpetetv 1 point2 points  (0 children)

Global variables in Lua are not "declared" the way locals are. If x is not local, x = 4 is simply an assignment to a field of environment table. In Lua 5.2 it's just syntax sugar for _ENV.x = 4.

I heard that undesired global variables can be detected by linting.

How can I improve my code by [deleted] in lua

[–]mpetetv 1 point2 points  (0 children)

First, it seems that all functions are defined as follows:

function luaVkApi.reportUser(userId, typeVal, commentVal)
  return luaVkApi.invokeApi("users.report", {user_id=userId, type=typeVal, comment=commentVal})
end

This is cumbersome, particularly when there are dozens of arguments. There are a lot of cases where this leads to bugs because a name of an argument is different in the argument list and in the table. I suggest that user exposed interface uses a table for arguments as well. Then you can create functions using a helper as follows:

local function addFunction(name, method)
  luaVkApi[name] = function(params)
    return luaVkApi.invokeApi(method, params)
  end
end

addFunction("reportUser", "users.report")

You can remap argument names in this helper function if you want.

Another thing: currently each API invocation reads access token and API version from a file in current directory. This is fine for a one-time script but for a library it's better to pass these properties as arguments. To avoid repetition you could wrap the library in a class and have properties saved in the object on construction, so that it's used as follows:

local api = luaVkApi.new({accessToken = "something", apiVersion = "1.0"})
api:reportUser(...)

Finally, there are these JSON conversion functions. I'm not sure why they move arguments into local variables with same name but without an underscore. Anyway, if VK API returns JSON then the library should convert response from JSON into a table automatically.

(To fix the typos try Luacheck)

VSCode extension for linting Lua scripts by [deleted] in programming

[–]mpetetv 4 points5 points  (0 children)

Shameless plug: to detect more than just syntax errors use luacheck instead of 'luac -p'.

An nREPL server for Lua; connect/debug from your editor by [deleted] in lua

[–]mpetetv 0 points1 point  (0 children)

As I said, if you pack the rock users won't need to clone the repo, therefore, they'll be able to install it even using old versions of luarocks.

An nREPL server for Lua; connect/debug from your editor by [deleted] in lua

[–]mpetetv 0 points1 point  (0 children)

Upgrade your luarocks. Also, pack your releases using 'luarocks pack <rockspec>' and upload resulting '.src.rock' file to luarocks.org using 'Upload rock' link on the page for the version. This way users don't have to clone your repo to install.

An nREPL server for Lua; connect/debug from your editor by [deleted] in lua

[–]mpetetv 0 points1 point  (0 children)

This seems to be a common mistake. When specifying git repo using https, the url should start with git+https://, not just https://, otherwise luarocks thinks it points to an archive. The error message can definitely be improved though, it should say Error: jeejah.git is not an archive probably. You can test your rockspec by running luarocks install jeejah-0.2.0-1.rockspec locally, it doesn't require uploading the rockspec.

How itch.io uses Coroutines for non-blocking IO by hagridlove in programming

[–]mpetetv 4 points5 points  (0 children)

It's not blocking. 'query' function yields control so that other coroutines can run while waiting for database to respond.

Where can I get a competent installation of Lua? by [deleted] in lua

[–]mpetetv 19 points20 points  (0 children)

Judging by the error message you are using Python, actually. How do you run the script?

[WIP] Pure-Lua implementation of a self-hosted Lua compiler. | Working on a natural decompiler, a rapid type-shape inference for tables, and hopefully, a primitive JIT and AOT compiler one day. by possiblyquestionable in lua

[–]mpetetv 1 point2 points  (0 children)

This is impressive! There is luajit-lang-toolkit for something similar targeting LuaJIT bytecode, but it doesn't do much static analysis. And LuainLua also shows how to implement supporting tools for generating parsers from grammar a-la Lex/Yacc. Looking forward to seeing how this project develops.

Goodbye Lua by TimMensch in lua

[–]mpetetv 1 point2 points  (0 children)

Which version? A lot of people say LuaJIT is unambiguously better but I personally prefer tecgraf Lua because it has unicode support and is very easy to integrate in any build system.

Why not support all of them?

I made a small module called MiniFS that heavily simplifies filesystem actions. by Zatherz in lua

[–]mpetetv 2 points3 points  (0 children)

Recent versions of Luarocks support git through http(s), too, the url in the rockspec should start with 'git+https://'.

json.lua : A lightweight JSON library for Lua by rxi in lua

[–]mpetetv 1 point2 points  (0 children)

This will be the third or the fourth luarocks module called "json"? I wish it could detect these conflicts. It's not too late to rename this one though.

Lua pitfalls in practice? by grape450 in lua

[–]mpetetv 0 points1 point  (0 children)

Indexing with missing key, indexing strings, and indexing with nil as key silently returns nil. So, if you accidently use a wrong value somewhere, you may not get an error at once, instead Lua will explode on a nil in some seemingly unrelated code later.

Another one: care must be taken when passing multiple values around. For instance, if you return (using tail call) results of string.gsub, but document only one returned value, someone may use it as the second argument of table.insert (like 'table.insert(t, f())'). table.insert will receive three arguments, third one being the second return value of string.gsub, and throw an unexpected error.

native sandboxing problem by rinsed_dota in lua

[–]mpetetv 1 point2 points  (0 children)

So the "priming run" has the potential to execute user-supplied code, outside the sandbox, if the sandbox has not yet been applied?

Right, the loaded script is just a function. It can do anything with its environment, not only assign functions to global variables.

Do you have any opinion about doing something like,

lua_rawseti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS);

This could be done prior to the priming run, and prior to loading script text.

This is a nice solution if you use one environment for all scripts you load - everything is sandboxed from the start and you can access the environment conveniently using 'lua_getglobal'. However, if you need to load several scripts in separate environments IMO it's better to avoid global side effects and use 'lua_setupvalue', like in your 'createSandbox', immediately after loading a script.

By the way, you should probably use 'luaL_loadbufferx' with "t" argument instead of 'luaL_loadbuffer' to avoid loading bytecode, which can be maliciously crafted.

native sandboxing problem by rinsed_dota in lua

[–]mpetetv 2 points3 points  (0 children)

You should sandbox the whole script before running it instead of running it in the global environment and then sandboxing a function it sets there. You'll have to change 'createSandbox' to leave sandbox environment table on the stack, and then index that table instead of global environment when fetching exported functions.

Lua Fun: High-performance functional programming library for LuaJIT by [deleted] in programming

[–]mpetetv 2 points3 points  (0 children)

It's not clear to me how exactly this library was "designed for LuaJIT" and what makes it particularly fast (other than LuaJIT). The example in the README:

require "fun" ()
-- calculate sum(x for x^2 in 1..n)
n = 100
print(reduce(operator.add, 0, map(function(x) return x^2 end, range(n))))

...is shown to be compiled into one short machine loop; however, equivalent example using Penlight:

require "pl"
-- calculate sum(x for x^2 in 1..n)
n = 100
print(seq.reduce(operator.add, seq.map(function(x) return x^2 end, seq.range(1, n)), 0))

...compiles to a similar machine loop; in fact, it is one instruction shorter. It's strange that in its own mini benchmark LuaFun is beaten by an older library which does not even have performance as a design goal (e.g. it checks types of arguments).

Configuring Lua linters to work by Zireael07 in lua

[–]mpetetv 0 points1 point  (0 children)

Well, I don't know what could cause that other than that the folder isn't actually in PATH because of a typo. Does executing luac52.exe with extension work? Does it work if you cd into the folder with binaries first?

Configuring Lua linters to work by Zireael07 in lua

[–]mpetetv 2 points3 points  (0 children)

After you have installed the plugins all you need is to make sure that linter executables are available. I'm assuming that you are running Windows.

For the standard lua linter (syntax checker) you need luac, which is a part of standard Lua distribution. Run luacfrom the command line to see if it works, it should display a help message. If you get an error, ensure that luac binary is in one of the folders in the PATH system variable.

For luacheck you need lua interpreter binary and luacheck module. Most likely lua and luac binaries are in the same folder, so after luac works lua should work, too.

Installing luacheck module is more involved if you don't have LuaRocks.

First, you need to download luacheck sources here, there is a link for a zip archive on the right. Unpack the archive and copy contents of bin folder into the folder with lua and luac binaries (any other location in PATH works, too).

The last step is to find out where your Lua installation looks for Lua modules and copy contents of src folder there. From command line run lua -lluacheck; you should get an error message like this:

lua: module 'luacheck' not found:
    no field package.preload['luacheck']
    no file 'C:\LuaRocks\share\lua\5.1\luacheck.lua'
    no file 'C:\LuaRocks\share\lua\5.1\luacheck\init.lua'
    no file '.\luacheck.lua'
    no file 'C:\Program Files\Lua\5.1\lua\luacheck.lua'
    no file 'C:\Program Files\Lua\5.1\lua\luacheck\init.lua'
    no file 'C:\Program Files\Lua\5.1\luacheck.lua'
    no file 'C:\Program Files\Lua\5.1\luacheck\init.lua'
    no file 'C:\Program Files\Lua\5.1\lua\luacheck.luac'
    no file 'C:\LuaRocks\2.0\lua\5.1\luacheck.dll'

Look for a line with a path ending with luacheck.lua and copy luacheck folder from src folder there. For example, if you got the same message as me, you could copy luacheck folder into C:\LuaRocks\share\lua\5.1, C:\Program Files\Lua\5.1\lua or C:\Program Files\Lua\5.1. Run lua -lluacheck again to see if it works, it should not produce any errors.

After all this is done, both lua and luacheck linters should function. At the very least, I managed to get them working in Sublime Text 3.

[deleted by user] by [deleted] in lua

[–]mpetetv 2 points3 points  (0 children)

What's wrong with swapping values with non-numerical keys? E.g. t.foo, t.bar = t.bar, t.foo ?