6 ms·
Could someone explain to me why would I choose this over https://github.com/openresty/lua-nginx-module https://github.com/openresty/lua-nginx-module ? It suppor
by chx 8y ago
Could someone explain to me why would I choose this over https://github.com/openresty/lua-nginx-module https://github.com/openresty/lua-nginx-module ? It supports LuaJIT and while I suppose it is possible to write faster C code by hand than JIT translated Lua it'd be hard and I'd fear the maintainability of hand optimized C code.
- kbenson 8y agoIt might be easier to tie in a few different external libraries if you're using C than with Lua FFI, depending on the libraries.
- legohead 8y agoIt's faster like you said. but probably the main benefit are people who have already developed a large program in C. C isn't hard to maintain -- it's not some mystical language..
- Something1234 8y agoIt just takes discipline. The discipline to not haphazardly throw macros all over the place, and keep them pure(no side effects).
- abstractbeliefs 8y agoSadly, the reason that discipline is such a vaunted virtue is because it's hard. Even the most well meaning and diligent C developers still make mistakes. Tools should be ergonomic, they should reduce the need for diligence, care, discipline, and intelligence. I'm not saying that the above aren't all important to programming, or that we should abandon anything that's not easy, but we're humans and make human mistakes and tools that are unforgiving when we do are ripe to be replaced by those that nudge us back on track.
- Something1234 8y agoMostly the compiler just needs to slap your hand harder, and tell you no when you do something stupid or depend on undefined behavior. Also better static analysis would be nice. I completely agree with you on all points. Languages exist to make our lives easier.
- abstractbeliefs 8y agoWell, there's a little more than that, as we actually have told compiler devs we don't want that. When developers demand that compilers compete with each other on fractions of a percent of runtime performance, we set ourselves up for things like UB acting in unintuitive ways. When people give us the choice between safer but slower systems, and fast but unsafe ones, until recently people have overwhelmingly chosen fast and unsafe and pretended they're superhuman enough to not write bad code.
- anonymoushn 8y agoThis is probably too much to ask for. I recently fixed an issue caused by UB in openresty of the form "nginx uses a NULL pointer and a length of 0 to signify a null string" + "nginx sometimes searches for strings in other strings using a function that takes start and end pointers for the haystack". This function works fine on lots of 0-length haystack strings (probably returning no match), but as you probably know, NULL + 0 is allowed to evaluate to anything. This seems pretty hard to detect statically short of banning programs that do arithmetic on any pointer without first NULL checking it.
- sureaboutthis 8y agoThat's why we choose to use C and do the other things, not because it is easy, but because it is hard, because that goal will serve to organize and measure the best of our energies and skills.
- comex 8y agoFor one thing, you don't have to use this module with C. Any language that supports exporting C-compatible functions will do – there's C++ of course, but also Rust, Go, D, Nim, and many many others.
- shakna 8y agoLuaJIT also supports C-functions. It's FFI [0] will allow you to declare any C-compatible function or data structure, and then use it in normal Lua code. [0] https://luajit.org/ext_ffi.html https://luajit.org/ext_ffi.html
- guipsp 8y agoWhy would you ever opt to go thru Lua in this case?
- shakna 8y agoIt's well supported, well maintained, and around for the foreseeable future. (OpenResty) The language implementation is fast, and allows you to tap into any C-compatible library. The question isn't why you would go through Lua, but why you would choose something with less support?
- Hello71 8y agoThis doesn't seem to support actually exporting C-compatible functions.
- shakna 8y agoCreate some Lua code that runs within C? Rather than just passing and converting to C values when needed? That's the role of the C API [0]. But usually you'd just be passing C up to Lua to bind it together. [0] https://luajit.org/ext_c_api.html https://luajit.org/ext_c_api.html
- annchin_peh 8y ago
- ksec 8y agoOr something "lighter" like H20 with mRuby? https://h2o.examp1e.net/index.html https://h2o.examp1e.net/index.html
- annchin_peh 8y agoHmm.. I've tried luaJit module and I've given up half way when building as it seemed a lot of compatibility issue(maybe not professional enough to build), sincerely I don't know lua and I prefer go for c module over any other language mixed together since nginx is build from C For nginx-c-function, it's easy build and I can build this as dynamic module and use it with other servers which has same version of nginx. It might be good to use lua if the person not good in c/c++.