Questions tagged [lua]

For code written in Lua, or built to interface with Lua (e.g. native code providing Lua functions).

Filter by
Sorted by
Tagged with
0 votes
0 answers
13 views

Pandoc Lua filter to prefix absolute paths of links and images

I rewrote one of my Pandoc filters (initially written in Haskell, then Python) as a Lua Pandoc filter. I'd be happy to receive feedback on how this filter could be improved, especially in regards to ...
Daniel Jour's user avatar
  • 1,581
3 votes
1 answer
1k views

Inverting a boolean in Lua

Is there a more elegant way to set this boolean value? SetScript() is a game API, while "OnClick" is its handler. What ...
user3713179's user avatar
0 votes
0 answers
50 views

Main menu for a LÖVE pong game

It's supposed to be the code for the main menu of a pong game I'm writing using LÖVE. I believe no knowledge on it is necessary for understanding, since it seems very explicit. I'm mostly unsure if ...
matticebox's user avatar
1 vote
2 answers
145 views

function to print any type in Lua?

I'm learning Lua for about a week now and I've built (I hope) a function to print any type in Lua. As I'm new to Lua I don't quite understand: if there is a more succinct way to achieve this if ...
Thiago Luiz's user avatar
4 votes
0 answers
197 views

First Lua program - Print external IP and VPN status

I started learning Lua yesterday and wanted to write a quick program as a practice. It queries an external service for the IP address and country code, and naively check for the existence of network ...
luanoob's user avatar
  • 41
0 votes
0 answers
125 views

Lua: print table at specific table depth

This is my custom function: ...
user3713179's user avatar
3 votes
1 answer
97 views

Trailing delimiter string splicing, implemented for Lua in C

I've been writing with C for a couple days, so this is a relatively advanced function compared to the simple things I've been doing previously. It's written for the Lua API, but it's still C. ...
wellinthatcase's user avatar
0 votes
2 answers
4k views

Get list of buffers from current neovim instance

The function below is written in Lua and returns the list of buffers from the current neovim session, it also allows the option to specify a optional table (object) as a parameter, with a ...
henriquehbr's user avatar
8 votes
2 answers
269 views

3D torus in Lua

I'm a total beginoob in Lua. The aim is to display a 3D Torus in dots (see Figure1), or at least compute the positions, privileging clarity over performance. Pseudocode link. Don't hesitate to be ...
YvesgereY's user avatar
  • 428
5 votes
1 answer
174 views

Complex number class in Lua

This is my first attemp with Lua. I decided to create this class, because it have lots of "tweaks" and "tricks". I want to know if I did it as best practices Lua ways. My Lua ...
Nick's user avatar
  • 1,480
4 votes
2 answers
513 views

I wrote my first pathfinding algorithm

I'm currently writing a small game in Lua, using the Love2d framework. I guess I'm doing it as a practice of sorts, but it did give me the opportunity to write my first pathfinding algorithm. I wrote ...
Rebecca's user avatar
  • 41
2 votes
0 answers
64 views

Hairy collision code

I have a lot of nested for loops is there a better way to organize this code? Also the way I add and remove enemies and lazers seems like a bad implementation. I set the index of the table to nil ...
dylan's user avatar
  • 397
2 votes
0 answers
51 views

Tile editor with increasing number of features

I've made a very simple tile editor. I'd like for someone to review my code and tell me what I could improve on. For example I'm bad at input management and creating systems that work nicely. Say I ...
dylan's user avatar
  • 397
2 votes
0 answers
670 views

Forum web scraper in Lua

I've written a short web scraper in Lua (run in LuaJIT for speed) to download every post from a specific forum (not general purpose... yet). It takes about 12 hours to run and download 500,000 posts ...
Allister's user avatar
  • 171
1 vote
0 answers
24 views

Processing commandline arguments [closed]

I'm parsing commandline arguments in lua with a command parser library (penlight lapp). This works fine, is easy to design and flexible enough for me. However, now ...
pschulz's user avatar
  • 111
3 votes
1 answer
220 views

Censoring words in lua

(repost: https://stackoverflow.com/questions/59665338/censoring-words-in-lua#comment105491094_59665338, as advised) Im currently making a discord censor bot for my friend, and I was wondering if ...
Albedo's user avatar
  • 31
1 vote
0 answers
194 views

Improving a code design of simple game mod for better teamwork [closed]

I've made this module in Lua as a mod for Project Zomboid game. In future I will develop my mods in a small team (of 2-4 programmers). At this moment I have no experience in teamwork, because most of ...
Maris's user avatar
  • 11
2 votes
1 answer
202 views

Convert an integer to 4 bytes without bitshift operators

This code is applicable to either GLSL or C due to virtually identical syntax. Before GLSL 1.3, bitshift operators were not present and I am aiming for backwards compatibility to GLSL 1.2. ...
J. H's user avatar
  • 179
6 votes
1 answer
520 views

Currying in Lua

Just whipped up this quick curry function in Lua, as a building block for partial application and memoization. Any feedback is appreciated. It takes two arguments; ...
user11536834's user avatar
3 votes
1 answer
382 views

Finite state machine for chasing and attacking a target

My questions are: How can I improve my implementation of the FSM model? Should Finite State Machines have functionality for Adding and Removing states from table? (Since I can only be in one state at ...
Mr Impact's user avatar
5 votes
1 answer
510 views

Recursive descent parser for simple arithmetic expressions grammar

What I'd like to see in your review, in order of relevance: Is there any bugs? (I see none, but...) Is the code efficient? (by whatever metric you'd like to use) Is the code easy to understand? ...
Gabriel's user avatar
  • 1,053
1 vote
1 answer
118 views

Building a 64 × 64 particle accelerator frame in Minecraft with a computercraft turtle

I dont think this will work anywhere besides in minecraft with computercraft but it's all correct syntax. I just feel like it has some lines of code I could eliminated somehow and made it a cleaner ...
Donnie's user avatar
  • 13
5 votes
1 answer
713 views

Collision detection for moving 2D objects

After implementing SAT (separating axis theorem) and not being happy with it only working on stationary shapes, this in theory allowing for fast objects to glitch through others, I came up with this ...
DarkWiiPlayer's user avatar
2 votes
1 answer
340 views

Faster way of converting a 1-d table to predefined userdata in Lua

I have defined a userdata in Lua (Lua version is 5.1) as shown below- ...
ravi's user avatar
  • 429
3 votes
1 answer
152 views

Serializing a table for filing

I have a table in Lua, which contains two 1-dimensional arrays in which each array contains approximately 800,000 elements. I want to serialize this Lua table to file efficiently. Hence, I planned to ...
ravi's user avatar
  • 429
5 votes
1 answer
978 views

Basic input validation package in Lua

I'm very new to Lua (and programming in general). I wanted to start out with a simple package that validates input based on a set of rules. The code works as intended, but is what I have written is ...
VirtualRaccoon's user avatar
4 votes
1 answer
354 views

Simple terminal-based Lua task-tracking/calendar

I am learning Lua and wrote this little calendar/time-tracking script. It allows me to create tasks to do with a deadline, print them, and mark them as being done. A task is a table with the following ...
frostblue's user avatar
  • 137
4 votes
1 answer
892 views

Wrapping an IntPtr in a Struct for safer Interop

Consider the following C#/C interop scenario: ...
Riley G's user avatar
  • 41
3 votes
2 answers
141 views

Generating a Lua script for a tile map maker

I'm using printwriter to generate a LUA script for a tile map maker. It seems hackish to me, but it works. Purposes are for allowing users to make their own maps for my game. Is there a better ...
Remixt's user avatar
  • 141
7 votes
2 answers
988 views

Shutdown-Script for Don't Starve Together Dedicated Server

I have written my first LUA-Script/Function to shut down the Dedicated Server for Don't Starve Together. I wanted to shut down the server in 2 minutes and inform everyone on the server that the server ...
Shinigami's user avatar
  • 215
7 votes
2 answers
3k views

Convert Lua UINT to hh:mm:ss

I have found the convert_to function in the lua-user wiki, and I created the convert_to_time function which does what I want it to do. Which is, basically: Having a number, return its value in a Time ...
Martin Router King's user avatar
2 votes
0 answers
374 views

Redis lua - game leaderboard "overview"

Here is the code I invoke as Lua script in Redis. I use Redis sorted set to store game scores. This function is used to get some kind of overview of leaderboard. It returns id, score and rank of: ...
odk's user avatar
  • 121
4 votes
2 answers
86 views

Suffixing numeric values

This is a part of my Factorio mod Visual Signals. This code takes a numeric value as input and returns a string for the value, for example: ...
Simon Forsberg's user avatar
1 vote
2 answers
434 views

Pico-8 player and scene

I recently started learning Lua by programming games in Pico-8. It's been fun, but it's time to learn some of the more powerful utilities to get things done smarter and with less redundancy. I'm an ...
user138468's user avatar
2 votes
1 answer
63 views

Load/save plain PPMs without error checking

I'm learning Lua. I decided to make a simple plain PPM decoder/encoder without error checks to familiarize myself with the language. I would appreciate any feedback on how could I make the following ...
Rusty Bludgeon's user avatar
6 votes
0 answers
131 views

brainF*** interperter in lua

For a personal project I may need to load and execute something that will basically be a very simple programming language. Though I am not at all close to this part of the project yet and I can most ...
lenscas's user avatar
  • 61
8 votes
1 answer
229 views

Hash-optimization and Wilson-maze generation algorithm

I've finished optimization of Wilson algorithm (maze generation) from "silly and slow" algorithm of choosing unvisited cells: ...
RussDragon's user avatar
11 votes
2 answers
1k views

Call a lua function - the C++ way

I'm not that good when it comes to templates, especially when it comes to variadic templates. I want to show you some code where I use both - templates and variadic templates - to call a lua function. ...
tkausl's user avatar
  • 614
8 votes
3 answers
240 views

print(fizz..buzz)

I couldn't help but notice we didn't have a FizzBuzz in lua yet. I've always wanted to take a shot at Lua, so here goes nothing. Code: ...
Mast's user avatar
  • 13.1k
0 votes
1 answer
344 views

Text based adventure game navigation

I have a problem with my code. I made so much code, and now I need to place ends, which I cannot figure out how to do because I need to line everything up and then place at least 5 or 6 ends in the ...
Dropdatderp's user avatar
3 votes
2 answers
888 views

Random RPG Battle System in Lua

This is my battle system that I wrote in Lua. Bear with me on this one, this is my first real program that does something besides write hello world. If there is anything that I could have done ...
Dropdatderp's user avatar
3 votes
1 answer
9k views

Simple four-operation calculator in Lua

I'm a beginner at Lua and programming in general and I just made a simple calculator and I was wondering where I could make improvements. ...
user avatar
2 votes
1 answer
73 views

Module to procedurally generate a map of islands

It chooses for each chunk some points inside that chunk that work as the center of each island. Then for each tile on the map it calculates the distance from the points in the 9 chunks around the tile'...
user6245072's user avatar
13 votes
1 answer
250 views

Implementing The Proper Undead's Cave Generator

I recently stumbled onto a very old article about procedural dungeon generation on this site. Unfortunately, the author did not provide any code, only a description of the algorithm he used. Wanting ...
Nikolai97's user avatar
  • 181
-2 votes
1 answer
716 views

Lua and complex numbers [closed]

I try to use complex numbers in a lua program. I need to parse a table of complex numbers printing side by side the name of the complex number and its value. Can't get through it : I don't ask how ...
Tarass's user avatar
  • 175
1 vote
2 answers
283 views

Simple maze game with four rooms

I'm starting to learn Lua and in one part of the book I need to convert a "Maze Game" that uses goto to another one that doesn't use ...
César's user avatar
  • 113
7 votes
1 answer
202 views

Lua/Love2D Resource Loader (Queue)

I made this resource queue in Love2D. ...
Accumulator's user avatar
5 votes
0 answers
576 views

Lua implementation of a text-based spreadsheets editor

Disclaimer: While the code in this question looks extremely long, I'm really only interested in reviewing some small parts of it. While I would sure appreciate someone going crazy and reviewing it ...
Not a real meerkat's user avatar
4 votes
2 answers
732 views

Bus Announcement System in ROBLOX Lua

I got bored and decided to create a lua announcement system with the ROBLOX API. One part is the display code, and the other part is the announcement code. DISPLAY CODE ...
PyxlWuff's user avatar
  • 471
6 votes
1 answer
2k views

Asynchronous request cloning using Lua + openresty

I'm working on a project to clone a subset of requests going to our production servers to one or more non-production endpoints. I opted to do this in Nginx and Lua because at the time, I could not ...
Ian Carpenter's user avatar