luajit

Do file only once in Lua

你离开我真会死。 提交于 2019-12-05 21:28:05
I was wondering if there's a way to do a lua file only once and have any subsequent attempts to do that lua file will result in a no-op. I've already thought about doing something akin to C++ header's #if/else/endif trick. I'm wondering if there's a standard way to implement this. James well, require pretty much does that. require "file" -- runs "file.lua" require "file" -- does not run the "file" again The only problem with require is that it works on module names, not file names. In particular, require does not handle names with paths (although it does use package.path and package.cpath to

Nginx 日志打印POST数据

只愿长相守 提交于 2019-12-05 20:33:15
在工作中,开发希望能从Nginx日志中获取POST的数据信息,先记录下来 在日志格式后面加上 $request_body 配置信息 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" $request_body'; 在server中添加打印日志的操作 access_log logs/access.log main;   本以为问题解决了,开发有要求在日志中添加上 服务器响应返回的数据 目前的 nginx 是不支持输出 response 报文体的 使用 body_filter_by_lua 来分配请求报文体给一个 nginx 变量。下面是一个示例 1:下载安装LuaJIT # wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz # tar -xzvf LuaJIT-2.0.2.tar.gz # cd LuaJIT-2.0.2 # make 出现如下内容表示编译成功 OK Successfully built LuaJIT make[1]: Leaving

Lua: understanding table array part and hash part

不羁岁月 提交于 2019-12-05 14:55:18
In section 4, Tables, in The Implementation of Lua 5.0 there is and example: local t = {100, 200, 300, x = 9.3} So we have t[4] == nil . If I write t[0] = 0 , this will go to hash part . If I write t[5] = 500 where it will go? Array part or hash part ? I would eager to hear answer for Lua 5.1, Lua 5.2 and LuaJIT 2 implementation if there is difference. Contiguous integer keys starting from 1 always go in the array part. Keys that are not positive integers always go in the hash part. Other than that, it is unspecified, so you cannot predict where t[5] will be stored according to the spec (and

lua_open returns null using luaJIT

风格不统一 提交于 2019-12-05 08:22:41
Using the recent luaJIT lua_open returns null . This does not happen with the regular lua library. lua_State *L = lua_open(); std::cout << L << std::endl; Output: 0x0 How can I get luaJIT to work? SSCCE: #include <iostream> #include <luajit-2.0/lua.hpp> //linked library: libluajit-5.1.a int main(int argc, const char * argv[]) { lua_State *L = luaL_newstate(); // lua_open(); std::cout << L << std::endl; // 0x0 } Additional information: Built on OSX 10.9 from source (tried both 2.0.2 and from git) with make and make install . Using compiler: $ cc --version Apple LLVM version 5.0 (clang-500.2.79)

Why is LuaJIT's memory limited to 1-2 GB on 64-bit platforms?

三世轮回 提交于 2019-12-05 08:11:58
On 64-bit platforms, LuaJIT allows only up to 1-2GB of data (not counting objects allocated with malloc ). Where does this limitation come from, and why is this even less than on 32-bit platforms? LuaJIT is designed to use 32-bit pointers. On x64 platforms the limit comes from the use of mmap and the MAP_32BIT flag. MAP_32BIT (since Linux 2.4.20, 2.6): Put the mapping into the first 2 Gigabytes of the process address space. This flag is supported only on x86-64, for 64-bit programs. It was added to allow thread stacks to be allocated somewhere in the first 2GB of memory, so as to improve

How catch ctrl-c in lua when ctrl-c is sent via the command line

冷暖自知 提交于 2019-12-04 22:49:38
I would like to know when the user from a command line presses control-c so I can save some stuff. How do I do this? I've looked but haven't really seen anything. Note: I'm somewhat familiar with lua, but I'm no expert. I mostly use lua to use the library Torch ( http://torch.ch/ ) Implementing a SIGINT handler is straightforward using the excellent luaposix library: local signal = require("posix.signal") signal.signal(signal.SIGINT, function(signum) io.write("\n") -- put code to save some stuff here os.exit(128 + signum) end) Refer to the posix.signal module's API documentation for more

How to check if nginx uses LuaJit and not Lua?

戏子无情 提交于 2019-12-04 22:47:04
I installed http-lua-module with nginx, made a script that works perfectly fine, but now I want to be sure that nginx uses LuaJit instead of Lua (because my research shows that LuaJit is faster). I added to the .bushrc those lines of code : export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH export LUAJIT_LIB=/usr/local/luajit/lib export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0 I also recompiled nginx and now I just want to be sure that it uses LuaJit. Edit your nginx.conf file, add a location into your server {} block: location = /lua { default_type text/plain; content_by_lua

How do install libraries for both Lua5.2 and 5.1 using Luarocks?

主宰稳场 提交于 2019-12-03 06:19:57
I am writing a small Lua project and using Luarocks to install my 3rd-party dependencies. The default Lua version on my machine is 5.2 and up to this point everything is working just fine. However, today I have stumbled across a problem that is confusing me. I want to run my program on Lua 5.1 and Luajit to see if it would also work on those versions but I am having a hard time getting Luarocks to download the appropriate versions of the dependencies. As a last resort hack, I have tried to tell Lua5.1 to use the 5.2 libraries that Luarocks installed (by setting the LUA_PATH environment

LuaJIT FFI load dll error

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to code some functions in C to use in Lua and the easiest way to do this I think I can find is using LuaJIT's FFI. I have a C file "add.c": int add(int a, int b){ return a+b; } I assemble it into "add.o" with: gcc -c add.c I make "add.dll": gcc - shared -o add.dll add.o Finally, I try to run the following Lua code in LuaJIT: local ffi =require("ffi") local test=ffi.load("C:\\users\\quebe\\Desktop\\add") ffi.cdef[[ int add(int a,int b); ]] print(test.add(1,2)) and get: luajit: test.lua:3: cannot load module 'C:\users\quebe\Desktop\add'

LuaJIT on Windows 10: unknown luaJIT command or jit.*

匿名 (未验证) 提交于 2019-12-03 01:36:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've been trying to install LuaJIT on Windows 10 for some time following the official guide , and I actually get to install it. For example, if I execute luajit I get into the prompt. Also, luajit -v returns the version of luajit (2.0.4). And I can also execute code with luajit -e <lua code> . However, whenever I try to save bytecode with luajit -b , I get the following message: luajit: unknown luaJIT command or jit.* modules not installed I tried to make all sort of installations: using Cygwin , luajit-rocks , MinGW , ... However, no matter