How do I run an executable using Lua?
You can use Lua’s native ‘execute’ command. Example: os.execute(“c:\\temp\\program.exe”) Sources: Lua Guide / os.execute
You can use Lua’s native ‘execute’ command. Example: os.execute(“c:\\temp\\program.exe”) Sources: Lua Guide / os.execute
There was a problem in the NodeMCU docs with the socket:send example you seem to have based your implementation on. We discussed it and I fixed it. An improved version of your code is this: gpio.mode(3, gpio.OUTPUT) srv = net.createServer(net.TCP, 28800) print(“Server created… \n”) local pinState = 0 srv:listen(80, function(conn) conn:on(“receive”, function(sck, request) local _, … Read more
You need to run math.randomseed() once before using math.random(), like this: math.randomseed(os.time()) One possible problem is that the first number may not be so “randomized” in some platforms. So a better solution is to pop some random number before using them for real: math.randomseed(os.time()) math.random(); math.random(); math.random() Reference: Lua Math Library
Using lbc instead of lmapm would be easier because lbc is self-contained. local bc = require”bc” s=bc.pow(2,1000):tostring() z=0 for i=1,#s do z=z+s:byte(i)-(“0”):byte(1) end print(z)
I hate having to install libraries (especially those that want me to use installer packages to install them). If you’re looking for a clean solution for a directory listing on an absolute path in Lua, look no further. Building on the answer that sylvanaar provided, I created a function that returns an array of all … Read more
I use LuaSocket to get more precision. require “socket” print(“Milliseconds: ” .. socket.gettime()*1000) This adds a dependency of course, but works fine for personal use (in benchmarking scripts for example).
Here is an implementation of a locals() function. It will return a table of locals from the calling scope: function locals() local variables = {} local idx = 1 while true do local ln, lv = debug.getlocal(2, idx) if ln ~= nil then variables[ln] = lv else break end idx = 1 + idx end … Read more
Based on the not-working, but well thought, idea of @Ilya Kobelevskiy here the final workaround: function pipeConnection(numIterations,inputFile) for i=1:numIterations while(exist(‘inputfile’,’file’)) load inputfile; % read inputfile -> inputdata output = myFunction(inputdata); delete(‘inputfile’); end % Write output to file % Call external application to process output data % generate new inputfile end; Another convenient solution would be … Read more
You need to run math.randomseed() once before using math.random(), like this: math.randomseed(os.time()) From your comment that you saw the first number is still the same. This is caused by the implementation of random generator in some platforms. The solution is to pop some random numbers before using them for real: math.randomseed(os.time()) math.random(); math.random(); math.random() Note … Read more
for k,v in pairs(second_table) do first_table[k] = v end