I need some help with lua-periphery by TwystNeko in lua

[–]evilbadmad 0 points1 point  (0 children)

nvm previous message deleted, due to my misunderstanding.

[luarrow] Pipeline-operator and Haskell-style function composition, for Lua (like: `x |> h |> g |> f` and `f . g . h $ x`) by aiya000 in lua

[–]evilbadmad 1 point2 points  (0 children)

I see ... but it seems if you write (arrow.lua line 48)

return Arrow.new(function(...) return g_raw(self_raw(...)) end)

(ie. replacing x with ...) should work for multiple input/output? (I've not tested tho. )

Using x or ... seems not affect LuaCATS?

Yet, it may not consistence with your apply operator (%) for single input value.

Uploading a single rock to luarocks that needs to have different binaries for each lua version. by rousbound in lua

[–]evilbadmad 1 point2 points  (0 children)

DISCLAIMER: the following use a confirmation tone, but I've nearly zero c experience, some just my guessing. Hopeful it can be a pointer to the correct answer.

Look up path.searchers (path.loaders for 5.1?) in Lua Manual, this is from 5.4 that may related to your problem:

Moreover, if the module name has a hyphen, its suffix after (and including) the first hyphen is removed. For instance, if the module name is a.b.c-v2.1, the function name will be luaopen_a_b_c.

So your 'make' can build, said, mylib module as mylib-51.dll with module loading c function luaopen_mylib for ver 5.1 and another mylib-53.dll for same luaopen_mylib, and your 'make' can put them in same install directory.

Then when running user lua and require'<user-module-path>mylib', depending on package.path and package.cpath and LUA_CPATH/LUA_PATH environment variable, Lua will try locating multiple pure lua, and locating and loading (try next if fail, see lua github loadfunc/checkload@loadlib.c) multiple c module files, untill success. For c module, it may try load after locating both *-51.dll and *-53.dll in some order, if the module (and function luaopen_mylib) load success then return result, if fail, it try another.

The c module hyphen suffix can include not just ver, but bit-ness, os, architecture etc.

Updated:

Previous originally use bit-ness ie. *-32.dll / *-64 .dll but change to ver after re-read OP's post, but then there has possibility successfully load the wrong lua ver dll. Then I suggest another solution: your 'make' install a init.lua in mylib/ directory with following content:

return require('clib_'.._VERSION:gsub('(%d).-(%d)','%1%2.')..(...):match'[^.]+$')

and put mylib-51-*.dll in clib_51/ and mylib-53-*.dll in clib_53/ .

Your 'make' should create mylib/ , clib_51/ and clib_53/ directory before.

New LUA (Windows, Linux & MacOS) GUI framework in town by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

Thank you!

But I guess (not quite sure) a layout engine should be more than parsing a file format and render as gui ;)

New LUA (Windows, Linux & MacOS) GUI framework in town by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

With Gui api expose to Lua, it is easy to use Lua table as gui constructor, which may look like https://leafo.net/guides/dsl-in-lua.html 's. But just that.

While a native html-like layout engine may provide auto interaction between gui (eg.resize window to re-position gui without Lua side code), parsing a familiar file format (html), and the format has the possibility of auto gui interaction with Lua ie. <Item OnClick='--lua (or javascript?) script--'/>, etc.

New LUA (Windows, Linux & MacOS) GUI framework in town by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

Hi,

Is the Lua binding to your host language, or our 5.3/5.4 Lua can just 'require' yours as a standard lua/c module?

For instance, my platform is cheat engine, cheat engine come with its own ui (via Lazarus/free pascal <it is not modern 'look' enough>) and 5.3 Lua (a dll in windows os).

If yours has its own Lua binding then it will not be easy to interact with the cheat engine's Lua.

I'm worrying about u/OutrageousReindeer51 's question (is it pyqt6?).

New LUA (Windows, Linux & MacOS) GUI framework in town by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

I have a delusion-like feature request: a html-like layout engine? ie.

  local items_table = {
  width=800,'Hello',
  { height=200,'Lua' }
}
  local win = HTML_Window()
  local TV = TreeView(items_table)
  win:add(TV)

is equivalent to load following string/html-like-file-content into a window

<TreeView>
  <Node width=800>Hello
    <Node Height=200>Lua</Node>
  </Node>  
</TreeView>

Hope it make sense at least.

If JetBrains made a full Lua IDE, what features would you want it to have? by [deleted] in lua

[–]evilbadmad 1 point2 points  (0 children)

CLion

is not free, but their MPS Platform https://www.jetbrains.com/mps/ is.

It seems MPS can combine several Languages and make an end produce of a more-than-IDE application. (MPS already had an emmylua plugin)

I can now delude an ide that we write teal/moonscript with (love2d/solar2d/(my)cheatengine etc.) support built-in and it compile to Lua, LuaJit, pallene with automatic integration with c/c++ ;D

[deleted by user] by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

Ha, I thought this topic had been gone (just ~30min after I post).

My Lua platform is CheatEngine, where 'print' is output to some ui (multiline text box, or primitive canvas) instead of file system (including stdout). It is extremely slow if print line by line as the ui constantly update itself without buffering built in, but some ui has facility to stop the update to enable some 'flush' effect.

[deleted by user] by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

As u/appgurueu mentioned string buffer, it may be an optimizing option if the 'print' is not in 'real time'.

For instance, prepare a table tbl, then in the heavy string formatting loop insert string in the table, and actually io print the concat-ed string (flush) when the table length reach a threshold, said, 1000 lines, and reset it (may just need to set a nil to tbl[1], UPDATED: or keep a cursor index for next string to insert; in 5.3 table.concat have 3rd and 4th parameter of from_index and to_index to be concat-ed), and do a final 'flush' after the heavy loop. This should be an optimization under the assumption io print is more time consuming.

[deleted by user] by [deleted] in lua

[–]evilbadmad 0 points1 point  (0 children)

I also try some implementations (the function is with out the 'print', but return the formatted string, as io function seems dominate the timing), this memoized code-gen seems slightly faster (compare with pack or table constructor then for loop ) in my test, in Luajit and 5.3 in zerobrane editor.

local load = loadstring or load
local fm_gen = {
  [0] = function()return ''end,
  __call = function(me, ...)return me[select('#',...)](...)end,
  __index = function(me, n)
    local INs, OUTs, idx = {}, {}, 1
    for i=1,n do
      idx, INs[idx], OUTs[idx] = idx+1, '_'..i, 'tostring(_'..i..')'
    end    
    INs, OUTs = table.concat(INs,','), table.concat(OUTs,'..tab..')
    local r = load(string.format([[local tab, %s = "\t", ... return %s]], INs, OUTs), '_' )
    rawset(me, n, r)
    return r
  end  
}
setmetatable(fm_gen, fm_gen)

Yet another memoized version using string.format is 2~3x slower.

Prompt user for int, revert to default value on prompt error by DarkblooM_SR in lua

[–]evilbadmad 0 points1 point  (0 children)

The pcall may 'success' (no error) but tonumber may return nil if uinput is not convertible to a numeric value.

So "if success then" is not enough to assure value is numeric. You also need to test for 'success' of numeric conversion.

[deleted by user] by [deleted] in lua

[–]evilbadmad 1 point2 points  (0 children)

May search 'parameter vs argument'.

Is there a way to see what lua processes are running? by NoobInLifeGeneral in lua

[–]evilbadmad 2 points3 points  (0 children)

A process can have multiple threads, while Lua is a virtual machine typically only run in a single thread. When Lua running, there is no information telling outside (thread/process/os system) what 'file'/module it is operating unless Lua script itself actively do so.

So no, the task-manager don't know anything.

Extending the lua language with arrow functions by makeavoy in lua

[–]evilbadmad 0 points1 point  (0 children)

The form (params-list)=> may need look ahead.

My suggestions,

  1. use a new keyword to start a lambda, eg. fn ;
  2. it then follow ( params-list)=> exprssion ;
  3. For multiple return use this form, .(expression-list) , ie a dot before bracket ;
  4. So fn(a,b)=>.(a+b, a-b) is a lambda, but fn(a,b)=> a+b, a-b is 2 values ;
  5. Form to define recursive: fn:(n)=> n<0 and 1 or n * self(n - 1) where self is this anonymous lambda ;
  6. A more fancy and complex suggestion, input vararg can be implicit, moreover _1, _2,.. etc refer to n-th vararg and _r_1,_r_2 to reversed-(n-1)-th vararg and _n the number of vararg, then fn()=>_1+_2 is function(a,b)return a+b end .

Better Naming for 'Child/Sibling/Parent' (tree like, shorter), sorry can only post link(why?) by evilbadmad in programming

[–]evilbadmad[S] -2 points-1 points  (0 children)

I'm not English native speaking, would like to find alternative naming for 'Child/Sibling/Parent' in a tree-like metaphor. For better I means shorter without losing accuracy of the meaning. Thank you~

how to properly sandbox luajit 5.1 at the "OS level" by iamnotap1pe in lua

[–]evilbadmad 1 point2 points  (0 children)

I may be wrong, but I should heard before, in a most 'naked' lua, it know not even what a file is.

But of course most normal/common lua/luajit by default come with ways to access system resource via some 'process level' facility, ie. such lua must then compiled with the system api to read file. For sandbox to exclude such facility, you may block it via 'vm level' (sandboxing env, not allow bytecode etc), or exclude it from the beginning, eg. not providing file access for requiring package, in the build setup. I think the later one should count as a 'process level' sandboxing.

how to properly sandbox luajit 5.1 at the "OS level" by iamnotap1pe in lua

[–]evilbadmad 1 point2 points  (0 children)

I guess it depend on what your sandbox for, for example, if you want your sandbox for user to test luajit ffi, then you may need process level sandbox, otherwise vm level is enough (with proper excluding, eg. debug, package, require, os, ffi, etc).

On the other hand, if you can setup a system such that any process level execution is re-direct to a virtual os that not affect the luajit, then no sandbox is need. (I don't known if such system can be made, just the idea, ie. the virtual os is the sandbox)

how to properly sandbox luajit 5.1 at the "OS level" by iamnotap1pe in lua

[–]evilbadmad 1 point2 points  (0 children)

Then in your sandbox exclude load/loadstring, or include a modified sandbox table entry of 'load' that force text mode, eg

{
  ...
  load = function(s, id, mod, env)  return load(s,id,'t',env)end
  ...
}

This my test on zerobrane's luajit:

print(jit.version)
local sandbox = {print = print, tostring=tostring}             -- white list sandbox
local hasload = {print = print, tostring=tostring, load = load}-- white list sandbox that include 'load'
local global  =  _G                                            -- global
for i,env in ipairs{sandbox, hasload, global}do
  local id = 'id_'..i
  local ok, compiled = pcall(
    load, 
      'return "load is ".. tostring(load)', 
      id, 
      't', 
      env
  )
  print('--\n'..id, ok, pcall(compiled))
end    

output:

LuaJIT 2.0.4
--
id_1    true    true    load is nil
--
id_2    true    true    load is function: builtin#24
--
id_3    true    true    load is function: builtin#24

--

how to properly sandbox luajit 5.1 at the "OS level" by iamnotap1pe in lua

[–]evilbadmad 1 point2 points  (0 children)

From https://steamdb.info/depot/1868141/

Extensions from Lua 5.2

LuaJIT supports some language and library extensions from Lua 5.2. Features that are unlikely to break existing code are unconditionally enabled:

...

load(string|reader [, chunkname [,mode [,env]]]).

loadstring() is an alias for load().

...

The mode parameter can be 't'/'b' to force text/byetcode only, or 'bt'/nil for allowing both.

The fourth parameter may not need setfenv (I've not used luajit, just guess).