What's a simple way to permanently add a directory to the Lua search path?
What's a simple way to permanently add a directory to the Lua search path?
Set the corresponding environment variable or rebuild Lua after adding your path to the source.
That library (and the one which it depends on) have no versioned release yet, so they are marked as DEV (which you can see in the "Versions" section). Those libraries do not show up in searches or can't be installed by default. You need to add the "development" repository in...
c++,arrays,lua,arguments,lua-table
The stack index -2 is the second to top element of the lua C stack. The arguments to your lua C function are also on the stack. So when you get two arguments your stack is <table>, <number> then you push a nil value and your stack is <table>, <number>,...
You don't use math.random to select a function; you use it to pick a random number, which you can then use as an index to get the function you need from a table (as one example): local list = { function() print(1) end, function() print(2) end, function() print(3) end }...
You need to call lua_next(L,-2) after lua_pushnil(L). You need lua_next because apparently you don't know the key in the table. So you have to use the table traversal protocol, which is to push the table, push nil, call lua_next(L,-2), and get the key and value on the stack. This works...
Since MyClass is just a lookup in the global table (_G), you could mess with its metatable's __index to return a newly-defined MyClass object (which you would later need to fill with the details). However, while feasible, such an implementation is wildly unsafe, as you could end up with an...
The following Lua library provides functions to (asynchronously) start and monitor processes. http://stevedonovan.github.io/winapi/...
Using == for functions only checks if they reference to the same function, which is not what you expected. This task is rather difficult, if not impossible at all. For really simple cases, here's an idea: function f(x) return x + 1 end local g = function(y) return y +...
It's better to avoid working with slopes and angles if you can avoid them, because you will have to deal with annoying special cases like when the slope is +ve or -ve infinity and so on. If you can calculate the normal of the line (blue arrow), then you can...
You can't. The Lua C API and the LuaJIT FFI are deliberately separated and cannot interact. Rewrite PrintC in Lua using the FFI, or write Lua C API bindings to the library you're using p with. I.e. Use one or the other....
You should push 1 and 2 on to the stack (or 0,1 if tables are 0indexed) and use lua_geti instead of iterating over the table with lua_next. Another example of how your current code is incorrect is what happens if the Lua user passes {1, 2, 3}? You would be...
function foo(param_1, param_2) -- obtain the default values local p1, p2 = getBar() -- combine the provided values with default values local bar_1, bar_2 = (param_1 or p1), (param_2 or p2) -- do whatever you need with bar_1 and bar_2 end If the getBar function call is expensive and should...
I know nothing about NodeMCU but that is not a proper http server. For it to properly work with a browser, it should return some headers. You can try to close the connection after sending the response. Try the following: wifi.setmode(wifi.STATION) wifi.sta.config("SSID", "password") wifi.sta.connect() srv = net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(conn,...
I still have to read the entire docs, but already found this: There are 16384 hash slots in Redis Cluster, and to compute what is the hash slot of a given key, we simply take the CRC16 of the key modulo 16384. There is a command for that op already:...
action = { [1] = function (x) print(1) end, [2] = function (x) z = 5 end, ["nop"] = function (x) print(math.random()) end, ["my name"] = function (x) print("fred") end, } You are free to do that....
Because that's what table.concat is documented as doing. Given an array where all elements are strings or numbers, returns table[i]..sep..table[i+1] ··· sep..table[j]. The default value for sep is the empty string, the default for i is 1, and the default for j is the length of the table. If i...
Yes, you can use compat-5.3 to get many of the newer lua C API functions in lua 5.1 (and 5.2). The particular function you're looking for (luaL_requiref) you can find here...
If you want to move sideways, you can simply add or subtract 90 degrees (in radians, that is π/2) from your r before calculating the sin/cos velocity vector.
I have solved this issue with the following code: local ffi = require "ffi" ffi.cdef[[ typedef struct { char *fpos; void *base; unsigned short handle; short flags; short unget; unsigned long alloc; unsigned short buffincrement; } FILE; FILE *fopen(const char *filename, const char *mode); int fprintf(FILE *stream, const char *format,...
You can always use NetworkManager which is available for installation in most official repos. It contains an applet which creates an icon at your system tray. You can launch the applet at start-up, placing this line in your rc.lua file: awful.util.spawn("nm-applet") or you can start it manually from your terminal,...
It looks as though you are not even using the X var... so why don't you try this... this is a more effective way to keep doing the same thing over and over while true do getTarg() derp1() sleep(2.9) monInit() end ...
There is Jan Kneschke's lua magnet of which I maintain a fork on github. I use this in conjunction with FastCGI (and luasql.sqlite3) for a small message board, which was previously written in PHP, then python. The PHP and python versions each performed so-so (which may be due to me...
You can use a subprocess to run your Lua script and provide the function with it's arguments. import subprocess result = subprocess.check_output(['lua', '-l', 'demo', '-e', 'test("a", "b")']) print(result) result = subprocess.check_output(['lua', '-l', 'demo', '-e', 'test2("a")']) print(result) the -l requires the given library (your script) the -e is the code that...
Simple detouring is easy to do with closures; no need for loadstring: function detour(cls) local detours = {} for key, value in pairs(cls) do if type(value) == "function" then -- note: ignores objects with __call metamethod detours["custom_detour_"..key] = function(...) -- Do whatever you want here return value(...) end end end...
osx,lua,osx-yosemite,libpng,torch
I had a similar problem (OSX 10.9.5). You probably have multiple versions of libpng installed, with the one called during install of luarocks having architecture i386 (x86_64 required). To solve this: Try installing image again, and reading the log: luarocks install image Check the log to see if you get...
Looks like a syntax error. message.Destroy() should be message:Destroy() according to this Roblox wiki page http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy Also see the section Explosions, Messages, and More at URL http://wiki.roblox.com/index.php?title=Basic_Scripting which provides similar syntax using the colon (:) operator....
local function Rotate(X, Y, alpha) local c, s = math.cos(math.rad(alpha)), math.sin(math.rad(alpha)) local t1, t2, t3 = X[1]*s, X[2]*s, X[3]*s X[1], X[2], X[3] = X[1]*c+Y[1]*s, X[2]*c+Y[2]*s, X[3]*c+Y[3]*s Y[1], Y[2], Y[3] = Y[1]*c-t1, Y[2]*c-t2, Y[3]*c-t3 end local function convert_rotations(Yaw, Pitch, Roll) local F, L, T = {1,0,0}, {0,1,0}, {0,0,1} Rotate(F, L, Yaw)...
c,multithreading,lua,erlang,ffi
If you can make the Lua code — or more accurately, its underlying native code — cooperate with the Erlang VM, you have a few choices. Consider one of the most important functions of the Erlang VM: managing the execution of a (potentially large number of) Erlang's lightweight processes across...
for-loop,lua,iterator,lua-table
You are creating the record table before creating the bid# tables. So when you do record = {bid1, bid2, bid3} none of the bid# variables have been created yet and so they are all nil. So that line is effectively record = {nil, nil, nil} which, obviously, doesn't give the...
When called without arguments, io.read() reads a whole line. You could read the line and get the words using pattern matching: input = io.read() opr, txt = input:match("(%S+)%s+(%S+)") The above code assumes that there is just one word for opr and one word for txt. If there might be zero...
lua,neural-network,backpropagation,training-data,torch
why the predictionValue variable is always the same? Why doesn't it get updates? First of all you should perform the backward propagation only if predictionValue*targetValue < 1 to make sure you back-propagate only if the pairs need to be pushed together (targetValue = 1) or pulled apart (targetValue =...
for-loop,matrix,lua,deep-learning,torch
See the documentation for the Tensor:apply These functions apply a function to each element of the tensor on which the method is called (self). These methods are much faster than using a for loop in Lua. The example in the docs initializes a 2D array based on its index i...
The bug is in lua_next(L, -2) line, because -2 refers to stack top minus one, which happens here to be the last argument to print. Use lua_next(L, i) instead. Upd: Lua stack indexes are subject to float when moving code around at development stage, so the general advice is to...
The purpose of this Lua function is only to provide a unique name. There are not many options in the standard Lua library. In other words, either you use what's available in Lua, or you write your own function. However, even if you use hashes, random numbers, and so...
Usually, the only things that would trigger a sort of tick, or cause a sizable amount of stoppage for a tick to pass by is pulling events (os.pullEvent,os.pullEventRaw,coroutine.yield) turtle movement does of course need a tick to go by, and do call coroutine.yield to pause the script and move. The...
lua,geometry,corona,geometry-surface
This sample from caronalabs.com forums shows how you might draw an arc, which provides the discrete algorithm you would need to do what you're asking: function display.newArc(group, x,y,w,h,s,e,rot) local theArc = display.newGroup() local xc,yc,xt,yt,cos,sin = 0,0,0,0,math.cos,math.sin --w/2,h/2,0,0,math.cos,math.sin s,e = s or 0, e or 360 s,e = math.rad(s),math.rad(e) w,h =...
Using a nested loop works. for lk, lv in ipairs(list) do for dk, dv in ipairs(database) do if string.find(dv.serial, tostring(lv)) then table.insert(copy, dv.img) end end end I'm using ipairs, which is similar to for i=1, #list do....
You are looking for string.char: string.char (···) Receives zero or more integers. Returns a string with length equal to the number of arguments, in which each character has the internal numerical code equal to its corresponding argument. Note that numerical codes are not necessarily portable across platforms. For your example:...
To fully understand the display.newText api of Corona SDK you can view it here: https://docs.coronalabs.com/api/library/display/newText.html For the Tap event you can view it here: https://docs.coronalabs.com/api/event/tap/index.html But I have fixed your code for you. But I really can't understand why you have "Impact" there. but here is a working code you...
The problem is the convolutional neural network from this tutorial has been made to work with a fixed size input resolution of 32x32 pixels. Right after the 2 convolutional / pooling layers you obtain 64 feature maps with a 5x5 resolution. This gives an input of 64x5x5 = 1,600 elements...
Short answer you can't. But, you can run an URL decode after logrotate. Here is the command : awk -v RS='\\\\x[0-9]{2}' 'RT{ORS=sprintf("%c", strtonum("0" substr(RT, 2)))} 1' ...
In Lua, the order that pairs iterates through the keys is unspecified. However you can save the order in which items are added in an array-style table and use ipairs (which has a defined order for iterating keys in an array). To help with that you can create your own...
Open a command line (e.g. under windows, that's cmd). Go into the directory where you have your local copy of XFuscator. Make sure lua is on your PATH. Type lua XFuscator.lua -h This should show the help message, which will describe the next steps....
Hi sid here you go: _W = display.contentWidth; _H = display.contentHeight; local button = {} x = -20 for count = 1,3 do x = x + 90 y = 20 for insideCount = 1,3 do y = y + 90 button[count] = display.newImage("imgs/one.png"); button[count].x = x; button[count].y = y;...
From C++, you could call luaL_dofile with the path to your file directly, then just call the function the usual way.
You may utilize integer part of the table to store keys in order: function add(t, k, v, ...) if k ~= nil then t[k] = v t[#t+1] = k return add(t, ...) end return t end t = add({ }, "A", "hi", "B", "my", "C", "name", "D", "is") for i,k...