This is not right! There are no arrays in lua.
Code like this would be completely valid
local t = { }
for i = 0, 2, 1 do t[i] = i end
And you would have your "array" t
start at 0.
Although, as stated by the lua.org page, "arrays" in lua are allowed to start at any index they want, but guess why, it's because they are not arrays, they are tables
Open Computers and ComputerCraft are minecraft (forge) mods that allow you to write and execute scripts written in the programming language Lua.
You can do some pretty crazy stuff with these mods because they can access the internet to download data and/or interact with other devices in the real world.
LUA? What's LUA? I only know of Lua.
> "Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
I think that is due to the fact, that the # operator is more like a max index operator, than a length operator http://i.imgur.com/HdRBm8p.png
what I don't really understand is the last one though
edit: from https://www.lua.org/manual/5.1/manual.html#2.5.5
"The length of a table t is defined to be any integer index n such that t[n] is not nil and t[n+1] is nil"
so it is like the "max index"
Edit2: added "like" to the last statement.
lua is a good language, not for it's feature set, but because it can easily be embedded. https://www.lua.org/ddj.html
this means that you can deploy a statically linked binary, and still have the option for a dynamic runtime. I often wondered why I saw lua everywhere, and this is why.
Well, for a start:
Smaller languages want more commercial exposure, so they advertise previous commercial success. It's not that complicated.
Oh, man. I've read a bunch of papers (well, skimmed most) but I don't do a good job of keeping track of them. One that comes to mind that is directly relevant to the book is "The Implementation of Lua 5.0" (PDF) which does a great job of explaining how they implement closures.
Pretty sure "I made hundreds of thousands of dollars off a game I designed and programmed" is good resume/portfolio material.
Most people aren't going to get as lucky as Jailbreak did but I don't think they'll ever have to work a day in their life again if they don't want to.
Even those who are mildly successful are making more in a month than they would in 3 at a normal job. Saying nobody uses Lua is just wrong, I'm not going to go into that. I think you meant to say, "knowing roblox lua doesn't make you a respectable programmer". https://www.lua.org/uses.html
And roblox staying active? I think the statistics and annual company growth speaks for itself..
Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
After that mod in ComputerCraft and let him play around with Lua. Just show and explain to him the ComputerCraft documentation and the Lua manual.
Convenience. Because it is largely used to "construct" new objects (in the manner of OOP for example), the first argument to setmetatable
is very often an (empty) table literal. See PIL code of an example.
This convenience lets you write
local set = setmetatable({}, Set.mt)
instead of
local set = {} setmetatable(set, Set.mt)
> "you really shouldn't make your own engine, you know?"
I just want to say, whoever said this is giving pretty garbage advice. Game engine development is one of the most stable careers in the actual games industry. Even if you don't make entire engines from scratch (though many companies do have home-grown engines - it's super common among MMOs), companies still need people to make specific modifications to off-the-shelf engines to better fit the needs of the project. Engine middleware development also uses the same skill set.
Anyway...
Lua's C API has a pretty small surface area. It can get a little complicated with the stack manipulation when you need to shuffle data in and out of it, but it's pretty easy to get a bird's-eye view of the whole API.
I'd recommend starting with the actual manual. It's not too long, relatively speaking, and it covers the API usage. Just remember to wrap your "#include" for the Lua API in "extern "C" {" and "}". It's a C API, afterall.
Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.
Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua
The full documentation for the language is provided here: https://www.lua.org/pil/contents.html
If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.
I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/lua) if you have any questions or concerns.
PiL explains that fairly nicely: https://www.lua.org/pil/16.html
But a TL;DR: In function declarations, using a colon adds a first parameter named "self". Those two below are completely identical:
local foo = {} function foo.bar(self, a, b, c) end function foo:baz(a, b, c) end
In function calls, and only where you call a function you index from a table, using a colon automatically passes the table itself as the first arg. See below:
local foo = { run = print } foo.run(1, 2, 3) --> 1 2 3 foo:run(1, 2, 3) --> table: 0xdeadbeef 1 2 3 print(tostring(foo) == 'table: 0xdeadbeef') --> true
Get yourself a project that uses Lua, or a Lua library like lua-posix. You'll just have to look at the structure of the code to get a good impression. Then read through the reference manual top to bottom [1]. If you need some more hints, the oldest edition of Progamming In Lua (targetting 5.0 but still relevant in large parts) is available for free [2]. Now, go back to your example project and try to understand parts of it, and then all of it.
Coming from a C background, what I had to write Lua<>C interops for was understanding how exactly upvalues work. But that's already an edge you're unlikely to touch if you don't exactly want to.
This, plus writing actual code, was all I personally needed.
> Also, do I need to learn another language before I can do this or to help me learn this?
It would be helpful to know some general concepts, but the materials in [1], [2] explain things by starting with the basics and then putting them together, so if you're really interested in engaging the subject you'll have a fun and productive learning experience even without prior knowledge.
[1] https://www.lua.org/manual/5.3/ [2] https://www.lua.org/pil/contents.html (I also recommend the paper book, if you want to afford it).
The tutorials on the Roblox wiki are pretty good for learning Roblox game development and Lua. http://wiki.roblox.com/index.php?title=AllTutorials
It might also be worth reading the Lua 5.1 manual, though not all things may apply to Roblox. https://www.lua.org/manual/5.1/
(Roblox uses Lua 5.1, but there are newer versions available. You just have to be careful when looking up things about it online. Thiss isn't usually a problem though as most things translate over.)
If you encounter an error or something you don't understand it's likely somebody has posted about it online, and very often it'll be on Stack Overflow.
Learning programming and game development involves lots and lots of practice. Don't feel bad if you're having issues in the beginning, you'll get better with time!
>what you resist, persists - C.G. Jung
I know what you mean. I held out for so long but now I use it daily. Good luck.
In respect to the game, what language would you like it have other than JS? I think Lua would be fun!
Programming In Lua is really great as a reference manual.
https://www.lua.org/pil/contents.html
If you like Minecraft, I recommend the mod CC:Tweaked (continuation of ComputerCraft). It's a lot of fun to play with and is substantially easier to learn compared to OpenComputers.
Look at, for example, the C API of Lua. (You didn't mention what sort of scripting language you had in mind, so I'll just guess Lua).
You can write C functions that are callable from lua. Some of those functions you write could, for example, register callbacks in the lua script that will subsequently be called (by your code) on some event occurring (which that event might be some interval of time passing, e.g. the callback might get called every 100ms, or every frame, or at 1Hz, or whenever a certain enemy gets killed, or what have you... completely up to you how you might make it work.)
/r/love2d for future reference
You're close. Formatting your code to fit on a single line makes it difficult to read, here's what it looks like formatted:
function stripecircle(r, x, y) for dtheta = math.pi, 0, -math.pi/512 do index = 0 if index%0 == 0 then love.graphics.setColor(1, 0, 1) -- set color to violet index = index + 1 love.graphics.line(rmath.cos(dtheta) + x, rmath.sin(dtheta) + y, rmath.cos(-dtheta) + x, rmath.sin(-dtheta) + y) else love.graphics.setColor(.5, .5, .5) -- set color to gray index = index + 1 love.graphics.line(rmath.cos(dtheta) + x, rmath.sin(dtheta) + y, rmath.cos(-dtheta) + x, rmath.sin(-dtheta) + y) end end end
The issue is that a new index
variable is created for each iteration of the loop. This is incorrect, you want a shared variable so each iteration will be reading and updating the same value. Something like:
function stripecircle(r, x, y) local index = 0 for dtheta = math.pi, 0, -math.pi/512 do if index%0 == 0 then love.graphics.setColor(1, 0, 1) -- set color to violet else love.graphics.setColor(.5, .5, .5) -- set color to gray end love.graphics.line(rmath.cos(dtheta) + x, rmath.sin(dtheta) + y, rmath.cos(-dtheta) + x, rmath.sin(-dtheta) + y) index = index + 1 end end
I haven't tested it but I think that should get you what you want.
A quick search gave me this paper: https://www.lua.org/doc/jucs05.pdf
Is this the one you are recommending? Even if it is not, it looks really cool so I would be reading it today :)
Last time (2017?) I checked inline-r
source was quite simple to follow. The difficulties aren't really on Haskell side, you rather need to read Embedding **X* in another application*; e.g.
You'll also need to do marshalling from X's data structures (some C
structs probably) to Haskell's. And in R example, there are ways to have cheap marshalling of primitive data, e.g. something like Vector of Doubles; which are common for R use case; the OP post also mentions ByteString
and JSVal
. I'd say, that as a task not much different than writing a parser FromJSON
parser; depending on X's API documentation though.
QuasiQuoter is a bit more tricky, as you'll need to parse X; in this JS case Tweag seems to do just lexing; anyway, whatever works :)
So TL;DR if you can embed language X into C-program, you'll be able to embed it into Haskell too. And actually the OP mentions most if not all parts. OTOH, to make a complete package, it takes quite a lot of time.
This is a little weird because Lua is designed for embedding. Embedded Lua VMs don't use the system path (/usr/local/lib/lua
) for finding files to require. That's used by the standalone <code>lua</code> executable that can be used for scripting or as an interactive shell.
require
is not actually built in, but is provided by the package library that's bundled with Lua. Embedders can opt in to using it using luaopen_package
. Crawl doesn't do that.
The require
function that Crawl does provide eventually uses datafile_path
to look up the location of the required file. This means that files are located relative to Crawl's own data directory (where levels, vaults, etc. are stored).
Long story short, if you want to require a Lua file, you'll have to drop it into your Crawl data directory. The one additional caveat is that Crawl loads files by reading them as strings and evaluating them. I believe the socket library you're using has a native component (a .so file), which won't work.
https://www.lua.org/pil/2.3.html - Lua doesn't have an equivalent of int
. Lua handles the bulk of the presentation & game logic. Hypothetical is that damage calculations is done with a c/c++ routine that returned an integer which was cast into a lua number variable (which overflowed) so that the damage logic saw positive damage but the user was shown a completely fucked up #.
I think the actual reason is history. They had two languages, realised they could combine them into a single new language, and created Lua from them. The predecessors didn't have local variables, so Lua ended up global-by-default.
I think it's a bad decision and local-by-default is the only sane choice, but it is what it is. It's a product of its time, because Lua and its predecessors were created at a time when bad defaults and footgun features were the norm because the language isn't supposed to hand-hold when you can just not make mistakes. The interest in having safe defaults and bug-prone features being opt-in instead of opt-out is a more recent thing in PL design.
> Lua has an official github repo.
> The Lua repo, as seen by the Lua team. Mirrored irregularly.
I'd say that's pretty much not official in any capacity. The official place to get the source code is the FTP source. Alternatively, all source pre-releases can be obtained from the working space.
> according to google, doing + should work but it always syntax errors
Not sure what you're searching to get that impression but +
is an arithmetic operator in Lua and is not used for string concatenation. If you search for "Lua string concatenation" (correct) or even "Lua string addition" (technically wrong) this page should show up high in the results with the correct operator: ..
You want to do "foo" .. "bar"
The Programming in Lua book is what I recommend. Lua's syntax is extremely easy to learn by example, so be sure to read the base/core game code (since the game's content is programmed in Lua).
Make sure to pay attention to the part on local variables and for loops!
The main thing that allows this, is that you can't use plain expressions as statements like you can in e.g. C. There's only a few select things, that are valid statements, like assigning or calling a function (ignoring its return value).
In the manual you can find all things that are considered statements written in EBNF:
stat ::= ‘;’ | varlist ‘=’ explist | functioncall | label | break | goto Name | do block end | while exp do block end | repeat block until exp | if exp then block {elseif exp then block} [else block] end | for Name ‘=’ exp ‘,’ exp [‘,’ exp] do block end | for namelist in explist do block end | function funcname funcbody | local function Name funcbody | local attnamelist [‘=’ explist]
Here's something funny I found out messing with it: if you go here: https://www.lua.org/cgi-bin/demo?demo you can see some of the code executed in the backend, and it also breaks the html. Actually, it searches for anything you write after the "?" in the url.
Someone should probably warn whoever maintains the website, there's some insecure code in there...
A good place to start is by browsing the official Lua website. On here you can find documentation on the language as well as a plethora of books and manuals designed to familiarise you with Lua.
it is running some lua code
local G=GetSpellInfo SetMacroSpell(GetRunningMacro(), G"Will of the Forsaken" or G"Will to Survive")
Essentially, it is setting the current macro to use whichever spell is available.
The most important part being G"Will of the Forsaken" or G"Will to Survive"
so that it uses will of the forsaken if you're undead or will to survive if you're human.
I don't know how much you know about programming, but that's what this is. World of Warcraft uses the Lua programming language for scripting (it is what everyone writes their addons with).
If you want to know more you could look at https://www.lua.org/pil/contents.html#P1
Lua's concatenation operator is not +, but rather ..
So you can do love.graphics.print("Name: " .. name, 69, 420)
You can also use lua's string.format function if you want to keep it all in one string:
love.graphics.print(string.format("Name: %s", name), 69, 420)
The benefit to string.format over the concatenation is that it may be more compact if you're trying to print lots of variables. However, if I'm trying to print just one var, I tend to use ..
Concatenation:
love.graphics.print("Variables: " .. a .. ", " .. b .. ", " .. c)
String.format:
love.graphics.print(string.format("Variables: %s, %s, %s", a, b, c))
> We'd rather not have to maintain a fork of std::collections::Map for just this feature, if possible.
You probably can't avoid it.
Lua implemented a hashtable and later wrote the specs for what happens during 'unsafe' access :
> The order in which the indices are enumerated is not specified, even for numeric indices. (To traverse a table in numerical order, use a numerical for.)
> The behavior of next is undefined if, during the traversal, you assign any value to a non-existent field in the table. You may however modify existing fields. In particular, you may clear existing fields.
So your options are :
Exact copy of lua: Even using a different hash function will give a different behavior. your best bet is to completely re-implement their next method and table.
Follow the specs: Maintain a fork. You don't have to worry about invalidating memory locations for most implementations because its UB creating new keys during iteration. But you have to watch out how you iterate over removed values .
Ignore the specs: Modifying a table during iteration is one of the dumbest things you can do in any language. Put it behind a lock and don't allow it.
I would choose the last and call it a feature. Code getting caught doing this should be modified anyways.
I see.
Couple of things I would critique about your approach:
> generates all possible combinations
Every design that includes a sentence like this almost always is slow (due to the exponential growth of "all possible combinations"), I'd strictly advise to only generate combinations that you actually need.
> generates functions based on it
How are these functions generated? Do you write actual c++ code to a file, compile it, link it in on the fly? If I had to guess you probably use std::bind
to fix certain parameters or something similar. In that case just storing those bound parameters in a sequence would be enough to quickly recreate those functions.
Lastly: 99.8312% (real statistic, btw) of all games use some kind of scripting language to resolve ingame logic. Specifically for things like weapon mods that usually require a lot of adaption/balancing hard coding them in C++ is often cumbersome. Have a look at lua. It's a lightweight, fast language that is fairly easy to embed in C++ programs.
This code is illegal because the lua grammar doesn't allow arbitary expressions as statements. Valid lua statements are function calls, assignments, function/variable declarations, for loops, if statements, etc
GetMediaTrackInfo_Value returns the value of whatever parameter, right? For B_MUTE it returns 0 or 1.
In Lua, when you test "if muted", you are treating muted as a Boolean value. Boolean values in Lua are kinda funky compared to other languages. Like I said, only nil and false are considered "False", and everything else is considered "True". So when you assign the API function value to muted, no matter what it returns, it will be considered "True".
The double == is a relational operator in Lua. It is testing for equality and returns a boolean value.
It feels weird from a programmer standpoint that I agree with, but Lua wasn't made for programmers originally. It was made as a configuration tool for software on oil platforms and made as easy as possible to make the workers on the platforms be able to debug and program the configurations themselves.
With that in mind, 1-indexing makes a lot of sense.
That was the story in my mind, according to their website: https://www.lua.org/history.html the story is about the same but a bit different. Interesting read.
Programming in Lua and the Lua Wiki Tutorial are my recommendations.
Lua is a general-purpose programming language, so it can be used for any purpose which is my Lua is also used to create games (and websites, etc.). The standard libraries (built-in functions) are very basic though, so you're going to need some kind of reference specific to your usage.
I'm so glad you asked! Without looking like too much of a sell out, I've made a series covering on how to learn Lua with specifically Isaac in mind. You can find it here:
https://www.youtube.com/playlist?list=PLKQ0xZyS4-67635Xkf8c5vG3O-l4a9vR1
This one focuses just on Lua specifically, the actual modding tutorials will come once we know how to use the Afterbirth+ API we'll be provided. With learning, there's always something for any person and if one thing helps someone learn, that same thing might not help someone else.
A good source (if you have prior programming experience) would be Lua's reference manual: https://www.lua.org/manual/5.3/
While it's not the best manual I've ever seen, it's still pretty darn good and allows you to quickly look up things.
I've mainly learned the little nooks and crannies off of this video: https://www.youtube.com/watch?v=S4eNl1rA1Ns
While it's not Isaac focused, if you're just looking up syntax, it's the way to go. In my videos I try to pose examples with Isaac in mind, so if you're new to programming and just want to learn how to make mods, I think that would be the best start, but if you're well versed in the black magic of programming, then any of the other sources should be enough to kick-start you creating some awesome things.
My apologies, I should have figured and provided a more in depth explanation of what a regular expression are, in my original answer and how to use them. If I would have done that explanation / research I probably would have found what I just discovered. It seems that Lua doesn't even have regular expressions.
SO, I poked around a little bit and made some code that seems to do the trick.
I've never worked with Lua before, but I tested the below code here and it seemed to worked fine. Let me know if this code makes sense / you have problems with it. Understanding what is happening in code you use is crucial to improving ;)
s = "Phantom was killed by big poison worm" s1 = "Some other log message"
player = " was killed by.*" cause = ".*was killed by "
function isDeathMessage(s) if string.find(s, player) ~= nil then p = string.gsub(s, player, "") c = string.gsub(s, cause, "") print(p) print(c) else print("Not a death message...") end end
isDeathMessage(s) isDeathMessage(s1)
according to this https://www.lua.org/manual/5.3/manual.html#3.4.10 You are wrong. "A call of the form f'string' (or f"string" or f[[string]]) is syntactic sugar for f('string'); that is, the argument list is a single literal string."
IIRC, Roblox hasn't moved from Lua 5.1 to 5.2 or 5.3.
Since 5.1 was released in 2006, I'd go with yes you can use that guide for learning scripting in Roblox.
Look here for the full version history, which also lists what the main differences between versions are.
EDIT: Oh and it's spelled 'Lua', not 'LUA'. And please don't make so many threads about the same topic.
if you haven't heard of it the require
function is the best way to use other lua files
some documentation:
https://love2d.org/wiki/require
https://www.lua.org/pil/8.1.html
and a tutorial:
Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.
Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua
The full documentation for the language is provided here: https://www.lua.org/pil/contents.html
If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.
I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/lua) if you have any questions or concerns.
No worries!
I recommend going through the official Lua language guide to help get the basics down. For your specific case, you're probably looking for if and else statements, which let you choose whether or not to run code based on some condition (in this case, the condition would be "has the ball hit this brick"). /u/megagrump's solution is a sensible one, but I'd say messing around with tables like that is Day 2 stuff if you're completely new to programming.
Do you have any sort of collision detection already working? e.g. determining if the ball has hit a brick, even if nothing currently happens as a result?
Source:
> To allow the use of Lua as a script interpreter in Unix systems, Lua skips the first line of a file chunk if it starts with #
. Therefore, Lua scripts can be made into executable programs by using chmod +x
and the #!
form, as in [...]
— https://www.lua.org/manual/5.4/manual.html#7
It's not even fair to say it's the shebang line it skips, as it would skip any first line starting with #
.
Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.
Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua
The full documentation for the language is provided here: https://www.lua.org/pil/contents.html
If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.
I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/lua) if you have any questions or concerns.
I've primarily taught myself the workarounds of Roblox's variant of Lua, I used two primary resources in my learning. A fairly decent way that many learn is from tearing apart 'free models' to see how they work, however, I would extremely advise caution if you go down this route.
​
To learn a bit more about Lua itself: https://www.lua.org/pil/contents.html
A resource regarding Roblox's API: https://developer.roblox.com/en-us/api-reference
Same here. I learned some basics by porting my dots [1] and nvim config [0] over. But still have a lot of question marks when I see lua code. Especially as nvim doc for lua is still early stage. If you want to sink you teeth into lua (future of nvim and all that) there's a free lua book on lua website [2].
Anyways, start small, step by step.
[0] https://github.com/vuki656/nvim-config [1] https://github.com/vuki656/dotfiles [2] https://www.lua.org/pil/contents.html
I started with Awesome a month or so ago and the first thing I did was read the first 7 or 8 chapters of this book on Lua programming that I found on the official Lua website. You definitely don't need to know all that info super well to be able to use Awesome but it helped with understanding the syntax and default rc.lua
. I then set out to understand the default config and break it out into separate files and directories because the default rc.lua
is a bit lengthy for me. While my config right now still looks very much like the default I have a much better understanding of what I need to do to customize further and am able to look at other people's code on github for ideas and tips. Of course, the official documentation is super helpful as well. Overall, I think it's a bigger up-front investment to use Awesome but so worth it allows for some really cool functionality you just cannot get with other WM's. Hope this helps and good luck!
Lua is very used by the gaming community in some engines but also mostly for embedding, as its very light and integrates amazingly well with C.
Also it's very simple to get started and very fast to start scripting, the syntax is very easy and clean. While javascript, even with ECMA6, not so much.
If you have any doubts with Lua, I do recommend the official Lua Manual, it's one of the best manuals out there, goes straight to the point.
functions are blocks of reusable code to do one or more actions. They may take input, they may not. For example, you could write a function that takes two numbers and adds them together:
function sum(a, b) return a + b end
(more: https://www.lua.org/pil/2.6.html)
local
variables are scoped variables. So basically if you define a local
variable within a function, it will disappear once the function has finished running (i.e. it is limited in scope to that particular function). Other variables are global and are available as long as the program is running (more: https://www.lua.org/pil/4.2.html)
I'd recommend going through the manual/tutorial from the beginning, or finding some other tutorials for beginners, otherwise you'll just end up back here asking similar questions (local scoping, especially, isn't a beginner/intuitive concept in my opinion)
Maybe it's a typo, because 2^21 is the first power of two higher than the highest valid Unicode codepoint.
edit: nope, it would appear to be correct:
> This library provides basic support for UTF-8 encoding. It provides all its functions inside the table utf8. This library does not provide any support for Unicode other than the handling of the encoding. Any operation that needs the meaning of a character, such as character classification, is outside its scope. > > Unless stated otherwise, all functions that expect a byte position as a parameter assume that the given position is either the start of a byte sequence or one plus the length of the subject string. As in the string library, negative indices count from the end of the string. > > Functions that create byte sequences accept all values up to 0x7FFFFFFF, as defined in the original UTF-8 specification; that implies byte sequences of up to six bytes. > > Functions that interpret byte sequences only accept valid sequences (well formed and not overlong). By default, they only accept byte sequences that result in valid Unicode code points, rejecting values greater than 10FFFF and surrogates. A boolean argument lax, when available, lifts these checks, so that all values up to 0x7FFFFFFF are accepted. (Not well formed and overlong sequences are still rejected.)
^ That is how I learned. Start with some simple addons and look through the code.
It's pretty similar to other C based function-driven scripting languages like JavaScript or PHP, but with its own quirks of course, so if you have coded in one of those languages before it shouldn't take too long to pick up.
If you're completely new to programming, it's probably not the best language to start out with in my opinion since the documentation is not very beginner friendly, especially with the WoW API on top of it.
To download the Lua binaries, head to https://www.lua.org/download.html.
​
They have pre-built binaries and source to build from with their respective Makefiles included for several different versions.
I usually go straight for the reference manual. You can find stuff pretty quickly with ctrf+F: https://www.lua.org/manual/5.3/manual.html
I don't know if someone made a neatly formatted "cheatsheet-style" reference for 5.3 though.
Except they're mutable and can also be indexed with integers~~, thus making them arrays as well~~. Also, you can start indexing them from whichever number you want, Lua doesn't care. You can write your own iterator to use in for loops for any special type of indexing you come up with.
They can also have holes and (mostly) function without problems, for example:
t = {} t[0] = "Hello" t[2] = "World!"
These wondrous constructs are called tables and they possess a separate name, because they're so ~~unkempt~~ unique.
Any table can also contain a table as its key and value. You can also have hybrid tables:
t = { ["name"] = "Nika", ["language"] = "lua" } t[1] = "one" t[2] = "two"
More on tables here: https://www.lua.org/pil/2.5.html
EDIT: added link to docs
You can use "classes" in Lua [https://www.lua.org/pil/16.html ]. Better yet, you can run Java inside python inside Lua inside Java.
It's actualy some of the best designed languages for scripting, in my opinion. Simple and flexible.
You are essentially asking for a way to convert a function into a human-readable string. This is pretty difficult in most programming languages, including Lua.
However, the exact opposite of your request is pretty easy: you can convert a human-readable string into a function using <code>load</code>.
s = "print('Hello')" a = load(s) a() -- Hello print(s) -- print('Hello')
So if you are looking to print the content of functions that you have written yourself, load
might help you.
You should be aware that if you are running Lua inside someone else's application (ex. in a game), the developers may have disabled load
. When making an application of your own, you should also recognize that running load
on a string that your users may have tampered with can be very unsafe (much like eval
in certain other programming languages).
Understanding the lua syntax is the first step, there are quite a few nice guides around the internet on the basics to lua.
I love using the lua reference to research the syntax of default lua whenever I'm in doubt on something. Roblox uses Lua 5.1; reference: https://www.lua.org/manual/5.1/index.html#contents
Then it's merely a matter of manipulating the "Instances" and "Services" that Roblox has created, in order to achieve creating what you envision as a designer/developer. A great tool for researching and understanding RBXLua is the Roblox Developer's Wiki.
The best way to quickly be able to script in RBXLua is to simply set yourself models to make, and to tackle making them using Free Models for reference, the developers wiki, and other internet resources. Patchworking together a basic understanding of the language just by powering through the struggle and using it will be the fastest way to get to a point where you can sit down and script something amazing.
Good luck with it :)
the function setmetatable
returns the table.
https://www.lua.org/manual/5.3/manual.html#pdf-setmetatable
>setmetatable (table, metatable) > >Sets the metatable for the given table. (To change the metatable of other types from Lua code, you must use the debug library (§6.10).) If metatable is nil, removes the metatable of the given table. If the original metatable has a __metatable field, raises an error. > >This function returns table.
(btw, Lua isn't an acronym).
That's what the documentation is for, I'd also suggest having a look at the PIL, programming in LUA before trying to start.
>No distinction between arrays and dictionaries/tables.
Not for the user, but Lua keeps arrays and hash maps separate internally.
​
>No integers only float for numbers.
​
>Strange for
loops (confusing?)
Agreed. Basic for i = 1, 10
is self-explainatory, but ipairs
and pairs
are not.
You can think of ipairs
as just a while loop that uses an incremental variable and stops when a table doesn't contain anything at that spot.
The latter will loop through the whole table (array and hash map parts), and while the order is technically undefined for the hash map, it'll still reliably query the keys sequentially if they're numbers (fun fact: reliably, starting at 0, not 1)
​
>Which edition of Lua do you prefer and recommend trying first?
Definately 5.3 and up, why? It has integers, bitwise operators, __pairs
which is nice for proxy tables. Why "and up"? Well, it has everything Lua 5.3 has and more, but one thing... one thing that bugs me... 5.3 doesn't have %p
for string.format
:D
There's also Moonsharp and recently open sourced Roblox's Luau.
Lua doesn't even have true regex, just something very similar. (explanation)
and if you wanted to parse HTML in Lua best the way would be with an external library anyways lol
Lua is a dynamic programming language which besides of numbers and strings only has these tables. They are like a hashtable and can be indexed by a number or string.
You can download the lua interpreter and look into ltable.c: https://github.com/lua/lua/blob/master/ltable.c
And here for for more information: https://www.lua.org/doc/jucs05.pdf
That's the way locals have always worked in Lua. <const>
is really just an offshoot of the <close>
attribute, so it only supports as much constant-ness as is required by a to-be-closed variable. https://www.lua.org/manual/5.4/manual.html#3.3.8
You'll need to learn Lua. There is no visual scripting. In my opinion Lua is a very beginner friendly language to learn. The tutorial section on the Defold website has lots of great examples to get stuck into.
The first edition of Programming in Lua (written by the language creator) is available for free online and is a great reference:
Finally, the forums and the Discord are very friendly if you get stuck.
Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.
Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua
The full documentation for the language is provided here: https://www.lua.org/pil/contents.html
If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.
I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/lua) if you have any questions or concerns.
The matching is trying to be "clever" by escaping the special characters used by Lua's pattern matching. (ref). One of these is "-"
so it would be escaped as "%-"
. The gsub
is meant to do that, except it changes it to "%%-"
instead. (My guess is this was translated blindly from a C-like language which uses backlash rather than percent, and to use a backslash in a string requires double-escaping.)
A solution is to change every "%%-"
to "%-"
. However, there's a better way. If you don't intend to use pattern matching, and are only looking to search for plain substrings, the find
function has a flag that turns off the special character handling. (ref) So that line would look like...
if iconpath:find(ICON_OVERRIDES[icons.appname], 1, true) then
As you can see, the extra call to gsub
is not needed. The other uses of find
can be adjusted accordingly.
Lua does not particularly have any serious bugs (that you will encounter). if you have a package, use the package manager, the latest lua version is not 5.3 but 5.4. so this is just a needless headache you're dealing with.
if you want to see the bugs, here they are: https://www.lua.org/bugs.html
When you open the mod editor, it'll open a help page. You're also welcome to dig through my mods: https://github.com/ChoGGi/SurvivingMars_CheatMods, if you have questions there's usually someone on the modders discord: https://discord.gg/vYHhrTP
The most useful tutorial I can recommend is https://www.lua.org/manual/5.3/manual.html
Time is never a "beginner" question. See http://www.creativedeletion.com/2015/01/28/falsehoods-programmers-date-time-zones.html
From the manual: https://www.lua.org/manual/5.4/manual.html#6.9
> os.date ([format [, time]])
> if format is the string "*t"
, then date returns a table with the following fields: year
, month
(1–12), day
(1–31), hour
(0–23), min
(0–59), sec
(0–61, due to leap seconds), wday
(weekday, 1–7, Sunday is 1), yday
(day of the year, 1–366), and isdst
(daylight saving flag, a boolean).
So that gets you the components of the time. Then test the min
and hour
fields.
return (min >= 58 and hour%2 == 1) or (min < 4 and hour%2 == 0)
Hi! It looks like you're posting about Logitech. Lua is used by Logitech G-series hardware to provide advanced scripting functionality. It does this by providing an API (application programming interface) which is essentially just a set of functions that you can use to tell your hardware to do things. The subreddit dedicated to Logitech G-series hardware is /r/LogitechG.
Your first port of call should be this document, which explains in detail the functions provided by the API: https://douile.github.io/logitech-toggle-keys/APIDocs.pdf
If you've familiarized yourself with the API but are still having trouble with the language and syntax, try this page for a quick rundown of Lua's main features: https://devhints.io/lua
The full documentation for the language is provided here: https://www.lua.org/pil/contents.html
If the above resources have not answered your question, /r/Lua is the place for you! If you're just trying to do something quick and don't want to learn Lua, head across to /r/LogitechG to find others of similar purpose.
I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/lua) if you have any questions or concerns.
If you want it easier to understand embedding/extending, you may want to look at Lua. It has an excellent API to work with C and it’s used in some areas like game engines, whose core is mostly written in either C or C++, and the scripting is done in mostly Lua or another language created with the purpose of scripting game logic. Some languages/implementations like CPython uses reference-counted objects to communicate with C, and some like Lua uses stack. This is a good place to start for Lua
https://www.lua.org/pil/ They have several official books, of which the oldest is 100% free online, but is slightly more outdated (It is 5.0 instead of 5.3 like the 4th edition).
As for WoW addons, honestly just using the various documentation online for the WoW API mixed with normal Lua is enough to get started on it.
Concatenation has performance issues if you do so inside a long loop.
The exact reasons are explained in Lua Performance Tips, page 8 of the pdf.
How to solve? Use table.concat.
The original poster makes a good point. Without knowing what you’ve done, its really hard to find what you are looking for.
With a google search, I was able to find the original Lua interpreter tests. https://www.lua.org/tests/ These can be used to test your interpreter. Have you done this yet?
Use pairs/ipairs
https://www.lua.org/pil/4.3.5.html
local t = { ["key1"] = "value1", ["key2"] = "value2", } for k,v in pairs(t) do print(k.." = "..v) end
local ti = { [1] = "value1", [2] = "value2", } for k,v in ipairs(ti) do print(k.." = "..v) end
Can't comment on what's best for your language without specific details, but you should definitely take a look at the annotated source of the Lua parser: https://www.lua.org/source/5.3/lparser.c.html - it is hand-written and provides excellent performance.
The Lua language provides a good example of how to design a minimal and fast, but powerful grammar.
FYI, "Lua" should not be all-caps. It's a Portuguese word for "moon", not an acronym. The official Lua reference manual is very well-written and a great way to learn the language, even for skimming as you try to learn on the job.
You can use a metatable. With the __newindex metamethod, you can keep track of table changes. See this article about __newindex.
In this example, the function onElementChange will be called every time a value is changed in the table. It will contain three parameters. The index of the changed value, the value that it contained before it was changed and the value that it contains after the change.
function onTableChange(index, oldValue, newValue) print("Value at index "..index.." changed from "..tostring(oldValue).." to "..tostring(newValue)) end
local array = setmetatable({}, {__newindex = function(t, i, v) onTableChange(i, t[i], v) rawset(t, i, v) end})
array[1] = 5 -- Value at index 1 changed from nil to 5
Note that you cannot do something such as array = {} because it will completely overwrite your array. The metatable will be lost and the function will not fire anymore.
In Lua, binary data is usually encoded as a normal string. Unlike in C, this works without problems as Lua strings aren't 0-terminated. It shouldn't be much of a problem to keep track of your padding that way, as the length of a string is not only its length in characters, but also its length in bytes, and you can convert between numeric values and string representations using string.byte()
(reference) and string.char()
(reference).
If your networking library takes care of converting the data to hex for you, I really recommend just making use of that instead, and doing all your other magic on the binary string. If you have any trouble with that feel free to come back and ask more questions :)
BTW: most of the questions here seem to be from people who are either new to Lua or completely new to programming, and I don't think people care at all about how silly they may get (And trust me, people have asked some pretty weird questions)
That's pretty cool. Lua has an online demo but it times out if you try to do anything that takes any time at all (I assume because it's executed on their own servers).
Your page freezes temporarily instead. Would you be able to implement it in a way that doesn't do that?
I recommend you learn Lua via PiL or LearnXInYMinutes. Get familiar with the Roblox API using the developer hub, as a senior developer you should pick this up fairly quickly. I'd avoid learning through material offered by or specifically covering Lua in the context of Roblox, most of these resources are pretty bad.
>What's in a name?
>"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!
It actually is. Functions that take a single string literal or table constructor argument can have their parentheses omitted at the call site.
>A call of the form f{fields} is syntactic sugar for f({fields}); that is, the argument list is a single new table. A call of the form f'string' (or f"string" or f[[string]]) is syntactic sugar for f('string'); that is, the argument list is a single literal string.
I essentially studied and followed other existing scripts and made small modifications until I learned what was responsible for what. Helped me learn rather quickly and I was kept interested.
Gradually, I started seeing other people script and learned what I was doing inefficiently in my own code, realized there were mechanisms I could’ve taken advantage of, and improved my form over the course of a few years.
You mentioned knowing how to use studio. If you can do that, I’d recommend checking out Programming in Lua, the official reference written by the designer of the language. You can gradually mix little things you gather about the ROBLOX API in with this. Otherwise, look at tutorials, and specifically look for ones regarding things you’d want to create.
In respect to ROBLOX, all of it never helped whatsoever in making me successful. I only made 13k ROBUX over those few years.
> I don't even know what interpreted could mean.
fwiw "the distinguishing feature of interpreted languages is not that they are not compiled, but that any compiler is part of the language runtime and that, therefore, it is possible (and easy) to execute code generated on the fly."
well, Lua as a whole is bigger than Isaac Lua. https://www.lua.org/pil/contents.html is a great source for learning base Lua (i recommend you at least look at some basic stuff) and then there are many YouTube tutorials for learning the Isaac part.
https://www.youtube.com/playlist?list=PLMZJyHSWa_My5DDoTQcKCgs475xIpQHSF this is a great tutorial series for Isaac.
If you use a pre-made library, it should be fairly manageable. My college had us embed Lua into one of our game projects early on, and that was surprisingly easy.
I haven't tried to run it yet, but people claim that Mono is good for embedding C#
If you're curious, here's the docs on Lua
Just a warning though: both APIs are based in C, so there will be a decent amount of pointer manipulation.
well there is no difference between
if ( (a == 1) and (b == 2) ) then
and
if (a == 1) and (b == 2) then
because Lua doesn't require parenthesis around the expression.
The remaining parenthesis can be left out too because ==
has a higher operator precedence than and
and so
if a == 1 and b == 2 then
does the same. The PiL manual has the full operator precedence table:
>Operator precedence in Lua follows the table below, from the higher to the lower priority: > > ^ > not - (unary) > * / > + - > .. > < > <= >= ~= == > and > or
^^https://www.lua.org/pil/3.5.html
and on the bottom there's a note: >When in doubt, always use explicit parentheses. It is easier than looking up in the manual and probably you will have the same doubt when you read the code again.
This is the reason that I personally would put parenthesis around the two sub-expressions (but not around the whole expression because that's just wasted characters and doesn't clarify anthing).
I used the manual: https://www.lua.org/manual/5.3/manual.html
But it sounds like you are new to programming, you may want to look for material specifically targeting someone who has never programmed before.
This question is way too vague. What exactly are you trying to do? Which things are you trying to pick out of a text variable? Do you mean a string?
If you're looking for ways to manipulate strings, what is provided is all in the string library.
What operating system are you trying to install it for? How are you trying to install it?
On many systems, the easiest way to get Lua is to download the source and build it yourself. This is easier for Lua than most applications that tell you to do this because of how portable Lua is.
Follow the directions on this page https://www.lua.org/download.html in the section called "Building". If you're on Windows, you'll either need to use Bash on Windows, or use Cygwin/MinGW.
If you are looking for a challenge, but for something that could eventually have a big impact, I've been working on new backends for the cross-platform native GUI library, IUP. IUP is a long-lived open source GUI library that provides a simple cross-platform API in front of native platform widgets.
The core IUP library and API are in C because that is the one language that works on every platform and can interoperate with every platform's native language. (And language bindings to any language are easy to create with a simple C API.) In this case, we use JNI to implement the native backend in Java for Android.
I just gave a talk at the renown annual Lua Workshop (IUP was created at the same university as Lua) about my new backends for Mac, iOS, Android, & Emscripten, but the video is not available yet. However, I have an older video introducing the iOS & Android proposals for IUP.
https://www.youtube.com/watch?v=UvrEfOg3Nyk
There is still much to do, and it would benefit from good native Android developers that can help make it both complete and figure out the best ways to implement things that feel natural to Android users.
The repo is here: https://github.com/ewmailing/IupAndroid
functions declared with the colon do implicitly have self as the first argument. "The colon syntax is used for defining methods, that is, functions that have an implicit extra parameter self. Thus, the statement
function t.a.b.c:f (params) body end
is syntactic sugar for
t.a.b.c.f = function (self, params) body end
"
The key and the value. See PIL Chapter 7.3.
Beware: this part of the the online version of the book is valid, but large parts of the rest are outdated. Fetch a recent copy at your local library/bookstore/hackspace/... if you want to learn Lua.
How about:
Store the numbers (or pointers to the numbers) as userdata
Expose some C functions to Lua that operate on this userdata
Write a Lua package that acts as an interface to the previous 2 parts