Lua - Reddit – Telegram
Lua - Reddit
30 subscribers
278 photos
31 videos
4.23K links
News and discussion for the Lua programming language.

Subreddit: https://www.reddit.com/r/lua

Powered by : @r_channels & @reddit2telegram
Download Telegram
ELM11 (Embedded Lua Machine) maker board

This is possibly of interest to readers of this subreddit - https://brisbanesilicon.com.au/elm11/.

I don't think I am breaking any 'R/LUA' rules by posting this here - apologies in advance if so.

https://redd.it/1mqo6fq
@r_lua
Help figuring out "requires" with c++ and windows

Hello,

I'm reading a book that teaches Lua and C++ together (Integrated Lua with C++), and I'm having difficulty figuring out how to accomplish this portion of the book. They use a Makefile and create a file called Destinations.SO, which is a Unix thing (I'm using Windows). I'm trying to figure out what exactly it wants so it can read it correctly.

Destinations = require "destinations" -- This loads `destinations.so` and assigns the module to the Destinations global variable.

I'm getting " Failed to execute: noscript.lua:1: module 'destinations' not found:" and a bunch of locations saying "no file 'D:....."

I'm going to provide the snippet of the book, and hopefully that makes it clearer:

>So far in this book, we have only explicitly registered C++ modules to Lua in C++ code. However, there is another way to provide a C++ module to Lua.

>You can produce a shared library for a module and place it in Lua’s search path. When the Lua code requires the module, Lua will load the shared library automatically.

>To test the standalone module, in the folder where `destinations.so` resides, start a Lua interactive interpreter and execute the following statements:

>Chapter09 % ../lua/src/lua
Lua 5.4.6 Copyright (C) 1994-2023 Lua.org, PUC-Rio
\> Destinations = require "destinations"
\> dst = Destinations.new("Shanghai", "Tokyo") Destinations instance created: 0x155a04210 > dst:wish("London", "Paris", "Amsterdam") > dst:went("Paris")
\> print("Visited:", dst:list_visited()) Visited: Paris
\> print("Unvisited:", dst:list_unvisited()) Unvisited: Amsterdam London Shanghai Tokyo > os.exit()
Destinations instance destroyed: 0x155a04210

>The most important statement is the require statement. This loads destinations.so and assigns the module to the Destinations global variable.

>We started the Lua interactive interpreter in the same folder where the module binary resides because require will search the current working directory for modules. Alternatively, you can put the library in a system search path. You can check the reference manual to learn more about require and its behaviors.

>A standalone C++ module is useful when you need to reuse the module in the binary form across multiple projects or enforce code isolation on the C++ side, but this is just a design choice.

Any help would be appreciated, because this is driving me crazy.

https://redd.it/1mrdml0
@r_lua
How do I even make a lua obfuscator?

I know someone already ask this but im asking like how does it work tbh I dont mind if it was fully made using lua like that prometheus obfuscator or using c or java of whatever type of programing language you know

https://redd.it/1mrsz35
@r_lua
Any simple ways a 13-year-old could earn money with Lua?

I’ve been learning Lua for about a year, mostly with Luau, and recently I’ve started using the LÖVE framework to make games. I’m 13 (in 8th grade), so I know I’m still pretty young, but I was curious: are there any simple or realistic ways for someone my age to make a bit of money with Lua coding?

https://redd.it/1ms83f2
@r_lua
Best Lua IDE?

Usually I just use Notepad++, but I have tried using Intellij with the Lua plugin and that was so-so.

Do any of you guys have suggestions?

https://redd.it/1msh79h
@r_lua
setmetatable and index

I'm doing more on classes - and I'm making a class


MyClass = {}
function MyClass:new()
o = {}

setmetatable(o, MyClass)
self.index = MyClass


return o
end

function MyClass:myfunc()
print("myfunc called")
end


c = MyClass:new()

I realise the manual example uses 'self' rather than MyClass - but I'm not looking for inheritance yet.

And I'm wondering why I need both to set the metatable and index to MyClass. Just setting the metatable fills the metatable of c with fields named after the MyClass functions (eg myfunc) that point to the metamethods - so they should be callable? Yet calling them is calling nil. Why do I require index to be set as well?
I've read the manual on the index metamethod and I see how setting index to the MyClass table and the index metamethod is called if there is no field in the metatable - yet the metatable of c has the field myfunc in even if I miss setting index.

https://redd.it/1mt5726
@r_lua
How to install a package in luajit?

I have tried to install packages in luajit using luarocks but it fails due to luajit’s maximum 65536 constants limitation.

1. Is there a way to install packages in luajit using luarocks?
2. What are other available alternatives?

https://redd.it/1mtl20b
@r_lua
Looking for FiveM developers

We are seeking a developer to assist our lead developer. Responsibilities will include everything from small fixes to adding new functionalities and features to our existing codebase.

We use a custom framework based on the Mythic framework. While the ability to build complete noscripts is not required, it is a plus. Experience with React and UI development is also beneficial.

Please note that we are not able to pay at this time; however, you will gain valuable experience and a meaningful journey in development. If you're new to FiveM and eager to learn, feel free to reach out.

DM > brains1960
In-discord



https://redd.it/1mtvbe6
@r_lua
where can i learn lua?

Im a 2nd year electrical engineer students, ive already learned c++ due to this (im no new to programming)

https://redd.it/1mus5we
@r_lua
can someone make me a cs2 no recoil noscript for all the guns with a simple toggle feature



https://redd.it/1mva4ty
@r_lua
Save system in Roblox Studio

Hi everyone,

I'm currently developing a multiplayer tycoon-style game in Roblox Studio where players manage animal mutant merger plots where they can build pens, hatch eggs, and merge animals.

Here’s the core design:

\- There are 5 unique plots in the world.

\- Players can scroll through and claim a plot they like.

\- Once claimed, they can build, place items, and interact with the world only within their plot boundaries.

\- There’s a central area with NPC shops where players can buy/sell items using an in-game currency.

What I Need Help With:

I’m trying to build a save system that:

\- Persists player progress across sessions (plot ownership, structures, inventory, currency, etc.)

\- Restores placed items on their plot when they rejoin and claim it

\- Supports respawning without losing plot ownership

\- Enforces build restrictions so players can only build inside their own plots

\- Is scalable, so I can add new features (animals, currency types, items) in the future without rewriting everything

I’m still very new to noscripting, so obviously I have been using GPT but have arrived at a dead end, what's the best way to go about this?

https://redd.it/1mvcjri
@r_lua
First time defining parameters of a custom function to create hexagon grid in TIC-80

So I want to make a civ-like game (eventually).

Today I decided to try and make just a grid and it was more complicated than I thought it would be.

First, I had to refresh my geometry knowledge. I confused hexagon with octagon, which was silly. But then I assumed diagonal lines are tilted at 45 degrees leading to me making very ugly hexagons. I went searching what angles do regular hexagons have and just to make sure, I double checked 30-60-90 triangle rules lol

So this is the final product and exactly what I was planning to achieve.

In the code I started with defining all points of the first hexagon and putting them into a list. I picked the length of each side equal to 8, starting with the top left diagonal line.
If you cut the upper part of a hexagon off, you'll get a triangle with 30-30-120 angles. You can then divide that triangle into two 30-60-90 triangles and calculate the distance between points as shorter sides of those triangles.

One is twice as short as hypotenuse. (8/2=4 which is the value of y1)

For the other I just used Pythagorean theorem.

Figuring out shift values was the most painful process and ngl a lot of it was guessing and intuition.

To actually draw a hexagon I used "for" loop of "line" function and added parameters to shift coordinates.

Then I created function to execute previous function in a loop while shifting it's x coordinates to create a row.

I added the same function, but with half of the x shift and full y shift. Hexagons aren't squares and can't just be stacked right on top of each other, but in between. Now it creates pair of rows which can be stacked without an x shift.

And finally... I just stack em.

I know it's not the clearest code, but it's 3am and I'm just happy it actually works despite me never setting parameters for a function before.

https://redd.it/1mvsv5n
@r_lua
Sentry SDK for Lua

This week is hackweek at Sentry (crash reporting service) and I wanted to try building an SDK for Lua:


https://github.com/getsentry/sentry-lua


The idea was to get a core set of Lua libraries (written in Teal) that are platform agnostic (aka: can run on standard Lua, LuaJIT, sandboxed in Roblox, etc) and then a set of platform specific libraries that could be used to have the SDK work on those platforms. For example, sending network requests.


It's very early days, but I got some CI that runs tests on Mac and Linux on different versions of Lua and LuaJIT. Some examples, including LÖVE (love2d framework) and Roblox. And I got it working on Xbox a minute ago but it's too duck taped to push so far, but I'll try to push this if not on the public repo, on a sentry-xbox private repo we can send invites to if folks want access.

https://redd.it/1mwnw38
@r_lua
LPEG and luajit: Lua is Awesome

This post may not be constructive or interesting, but I need to share my enthusiasm.

I started writing a VM entirely in Lua for my Plume language.

The idea was that "the VM will be horribly slow (inevitably, since it's an interpreted language running an interpreted language), but it's a prototype that can be ported to C later."

For parsing, instead of my "clean and serious" code, I thought, “Well, LPEG seems pretty solid, I'll do something quick and dirty just to get the AST out in one pass.”

In short, "quick and dirty" for prototyping. How wrong I was!

LPEG is monstrous. Very demanding in terms of abstraction, but once you understand the principle, it allows you to parse complex grammars with ease.

But parsing isn't everything: you can arbitrarily modify the capture flow in a simple and transparent way.

In the end, my "quick and dirty" code was shorter, more efficient, and easier to read than the old "clean code".

As for performance... Remember, a VM written in Lua isn't going to be lightning fast, right?

Well, thanks to the black magic of luajit, on the few benchmarks I wrote, Plume outperformed Lua 5.1 by 30%. Yes, on a 1-week dirty VM.



Lua is awesome.

https://redd.it/1my4byk
@r_lua