Hello,
I created a small lua code to create a board (just a matrix with objects that can move). I want to use this code to create both a game of chess and a game of checkers. Is there a way of turning this code onto a library I can just import and call my buildBoard() function? I know that such a small code should probably just be written onto my main.lua, but I did this exactly as a way of learning more about libraries.
Thx in advance.
How to turn my code onto a library
- BrotSagtMist
- Party member
- Posts: 659
- Joined: Fri Aug 06, 2021 10:30 pm
Re: How to turn my code onto a library
For yourself or for others?
For yourself you can just outsource code and require makes it behave as if its still in the main file, nothing special there.
If this should be used by others as a general lib the structure is
So require returns the table lib with everything in it there is to access.
Libs should further never create globals or mess with them.
For yourself you can just outsource code and require makes it behave as if its still in the main file, nothing special there.
If this should be used by others as a general lib the structure is
Code: Select all
local lib={}
local stuff
lib.start= function()
otherstuff
end
return lib
Libs should further never create globals or mess with them.
obey
Re: How to turn my code onto a library
Got it, thank you
Re: How to turn my code onto a library
Is there a way to compile lua into .so lib? And then import this in a project? Maybe he is asking something like this because he does not want to share the source code with other or does not want to copy the same lib files to multiple projects he is working at?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: How to turn my code onto a library
you can compile lua code with luajit if you're really hard pressed to obfuscate it, but it's worthless and detrimental in so many ways.Rigachupe wrote: ↑Tue Aug 02, 2022 4:38 am Is there a way to compile lua into .so lib? And then import this in a project? Maybe he is asking something like this because he does not want to share the source code with other or does not want to copy the same lib files to multiple projects he is working at?
just use a license file and threaten lawsuits like a sane person
as for not copying the same files to multiple projects, symlinks exist.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: How to turn my code onto a library
I saw a Lua to C compiler, https://github.com/davidm/lua2c but in my testing the resulting executable was slower than Lua, and of course much slower than LuaJIT.
Re: How to turn my code onto a library
For future reference, check the modules tutorial on Lua Users Wiki. There are plenty other good articles on there for all things Lua. Check it out!
Who is online
Users browsing this forum: No registered users and 8 guests