Found 33676 Articles for Programming

Differences between Javascript and Lua programming

Mukul Latiyan
Updated on 20-Jul-2021 14:08:31

335 Views

We know that there’s a huge gap in the popularity and use-cases of JavaScript and Lua. Besides this gap in popularity and use-cases, these languages have many differences at code level.The following table highlights some of the most notable differences between JavaScript and Lua.KeyJavaScriptLuaImplicit conversion when comparingJavaScript does implicit conversion when it is comparing any two objects with either the == or != comparison operators.Lua doesn’t convert between the types when it uses the comparison operators.Operator precedenceIn JavaScript, the ==, ===, != and !== operators are of lower precedence than >, >=,

Difference between . and : in Lua programming

Mukul Latiyan
Updated on 20-Jul-2021 14:07:09

6K+ Views

The .(dot) operator in Lua is used to invoke the method of an object, and it is a widely used operator in Lua.The :(colon) operator in Lua is used when you want to pass an invisible parameter to the method of an object that you are calling.Let’s consider an example where we will have an object in which two functions are present and we will try to access these functions, first by making use of the dot operator and secondly by making use of the colon operator.ExampleConsider the example shown below − Live DemoreturnX = {foo = function(x, y) return x ... Read More

Concatenation of tables in Lua programming

Mukul Latiyan
Updated on 20-Jul-2021 14:05:05

9K+ Views

We can append two tables together in Lua with a trivial function, but it should be noted that no library function exists for the same.There are different approaches to concatenating two tables in Lua. I’ve written two approaches that perform more or less the same when it comes to complexity.The first approach looks something like this −function TableConcat(t1, t2)    for i=1, #t2 do       t1[#t1+1] = t2[i]    end    return t1 endAnother approach of achieving the same is to make use of the ipairs() function.ExampleConsider the example shown below −for _, v in ipairs(t2) do   ... Read More

Concatenation of strings in Lua programming

Mukul Latiyan
Updated on 20-Jul-2021 14:03:40

3K+ Views

Concatenation of strings is the process in which we combine two or more strings with each other, and in most of the programming languages this can be done by making use of the assignment operator.In Lua, the assignment operator concatenation doesn’t work.ExampleConsider the example shown below − Live Demostr1 = "tutorials" str2 = "point" will throw an error s = str1 + str2 print(s)Outputinput:7: attempt to add a 'string' with a 'string'Hence, the most straightforward way is to make use of the concatenation keyword which is denoted by .. (two dots)Let’s consider a few examples of the concatenation keyword in Lua.ExampleConsider ... Read More

Command Line arguments in Lua

Mukul Latiyan
Updated on 20-Jul-2021 14:00:08

6K+ Views

Handling command line arguments in Lua is one of the key features of any programming language. In Lua, the command line arguments are stored in a table named args and we can use the indices to extract any particular command line argument we require.Syntaxlua [options] [script [args]]The options are −-e stat− executes string stat;-l mod− "requires" mod;-i− enters interactive mode after running script;-v− prints version information;--− stops handling options;-− executes stdin as a file and stops handlingoptions.ExampleLet’s consider an example where we will open a Lua shell in interactive mode and we will pass the script as dev/null and then we ... Read More

Code indentation in Lua Programming

Mukul Latiyan
Updated on 20-Jul-2021 13:53:46

4K+ Views

Lua codes are not like Python when it comes to indentation. So, most of the code you will write will work even if it falls on another line, and you don’t necessarily need to have the nested code to be intended by a certain tab size.The code indentation in lua is more about making the code look much better and more readable. If your entire code is on one line or worse, if it is like multiple lines then I am afraid that your code isn’t very readable.While we can use the code editor’s indentation packages to do the indentation ... Read More

Array Size in Lua Programming

Mukul Latiyan
Updated on 20-Jul-2021 13:52:36

5K+ Views

It is a general convention that the size of the array is the number of elements that are present inside the array before the nil. In many cases, nil is not allowed in the array, but for some applications, it is not an issue to have nil inside them.If we allow nil values inside the array, then we must have some functions to set the size of the array explicitly.Lua does provide us with two functions to manipulate the size of the array and these are −setngetnThe setn function is used to set the size of the array explicitly and ... Read More

Alternatives to Lua as an Embedded Language

Mukul Latiyan
Updated on 20-Jul-2021 13:50:23

888 Views

An Embedded language is a language that can be used in an application. It is a programming language that adds an ease of performing operations in a specific application.There are many embedded languages that you can use, the most common ones are Lua, LISP, VBA etc.When it comes to choosing the best embedded language, there are several factors that we need to consider. The most basic factor would be to know what are the basic drawbacks that one can have regarding the use case of the language.While Lua does a pretty good job to check or satisfy most of the ... Read More

__tostring element in Lua Programming

Mukul Latiyan
Updated on 20-Jul-2021 13:46:34

2K+ Views

The _tostring element in Lua receives an argument of any type and converts it to a string in a reasonable format.If the metatable of e has a "__tostring" field, then tostring calls the corresponding value with e as argument, and uses the result of the call as its result.The __tostring element method is a part of the metatables that Lua library provides us and is used to modify the behaviour of the table that we get as an output.The __tostring element method is used to modify the behavior of the output table.Example Live Democurrtable = setmetatable({ 10, 20, 30 }, { ... Read More

io.popen() function in Lua Programming

Mukul Latiyan
Updated on 20-Jul-2021 13:43:35

16K+ Views

Sometimes we want to execute the system's command and then make use of whatever was returned by them, and in order to do that we simply can either make use of the os.execute() function or io.popen() function.The difference between the os.execute() function and the io.popen() function is that the output value of the os.execute() function is much harder to deal with, and that is the reason why it is recommended to use the io.popen() function, whose output value is much easier to handle and make use of.io.popen() starts the program in a separate process and returns a file handle that ... Read More

Advertisements