File tree Expand file tree Collapse file tree 4 files changed +24
-28
lines changed Expand file tree Collapse file tree 4 files changed +24
-28
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ title: Creating a Project
4
4
---
5
5
6
6
In the next chapters we will learn how to create, manage and publish a small Lua CLI
7
- that checks whether the entered words contain "hello" or not .
7
+ that checks whether a sentence provided to the program contains the string "hello".
8
8
We will cover dependencies, the ` lux.toml ` format and more all the way up to API keys!
9
9
10
10
To start writing Lua, we must initialize a project where we will store our code.
@@ -44,26 +44,35 @@ can be safely ignored.
44
44
You'll see that our ` my-lua-project/ ` directory was created. Let's enter the directory
45
45
and get to work!
46
46
47
- Inside of our project, you should see that a single file was generated :
47
+ Inside of our project, you should see that a basic project skeleton was created :
48
48
49
49
``` bash title="tree $(pwd)"
50
50
/home/your-username/my-lua-project
51
- └── lux.toml
51
+ ├── lux.toml
52
+ └── src
53
+ └── main.lua
52
54
```
53
55
54
56
The ` lux.toml ` file describes instructions on how to build and ship your Lua code.
55
57
Let's enter the file. You should see contents similar to the following:
56
58
57
- ``` lua title="lux.toml"
59
+ ``` toml title="lux.toml"
58
60
package = " my-lua-project"
59
61
version = " 0.1.0"
60
- lua = " >= 5.1"
62
+ lua = " >=5.1"
61
63
62
64
[description ]
63
65
summary = " A sample project."
64
66
maintainer = " vhyrro"
67
+ labels = [ " learning" ]
65
68
license = " MIT"
66
- labels = [" learning" ]
69
+
70
+ [dependencies ]
71
+ # Add your dependencies here
72
+ # `busted = ">=2.0"`
73
+
74
+ [run ]
75
+ args = [ " src/main.lua" ]
67
76
68
77
[build ]
69
78
type = " builtin"
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ This may take a while depending on your internet connection!
19
19
20
20
## Testing Our Changes
21
21
22
- To check whether ` argparse ` is loaded we can enter a Lua REPL and play around
22
+ To check whether ` argparse ` is loaded, we can enter a Lua REPL and play around
23
23
with our code. However, just running ` lua ` will not work. To enter a
24
24
` lua ` REPL with our dependencies loaded, we need to run the following command instead:
25
25
Original file line number Diff line number Diff line change @@ -3,25 +3,10 @@ id: making-the-application
3
3
title : Making the CLI Application
4
4
---
5
5
6
- Lux expects to find code under either a ` src/ ` or ` lua/ ` directory.
7
- For this series, we'll store our code under ` src/ ` .
6
+ ## Creating the Skeleton
8
7
9
- Inside the project directory (where your ` lux.toml ` resides) create a ` src/main.lua ` file.
10
- This acts as the main file Lux will execute.
11
-
12
- Here's what your project directory should look like after creating the file:
13
- ``` sh title="tree ."
14
- .
15
- ├── lux.toml
16
- └── src
17
- └── main.lua
18
-
19
- 2 directories, 2 files
20
- ```
21
-
22
- ## Ensuring the Project Runs
23
-
24
- Let us add the following boilerplate code to ` src/main.lua ` :
8
+ Let's add some simple boilerplate using ` argparse ` . This program will print back anything
9
+ we pass as arguments back into the console:
25
10
26
11
``` lua title="src/main.lua"
27
12
local argparse = require (" argparse" )
@@ -36,10 +21,10 @@ local args = parser:parse()
36
21
print (args .input )
37
22
```
38
23
39
- We're now ready to see if our code works! Run the following command to see your code in action:
24
+ Run the following command to see your code in action:
40
25
41
26
``` sh
42
- lux run " Testing our code!"
27
+ lx run " Testing our code!"
43
28
```
44
29
45
30
You should see ` Testing our code! ` printed right back at you in the console!
Original file line number Diff line number Diff line change 52
52
end
53
53
```
54
54
55
+ Noticed how we replaced the function with a ` require ` call to the new file.
56
+
55
57
## Writing our First Test
56
58
57
59
Now that we have our code structured, let's write our first test. Tests are usually stored in
81
83
## Running the Tests
82
84
83
85
We're now ready to run our tests! ` lx test ` will run all the tests in your
84
- project. After the automatic installation of ` busted ` you should see the following output:
86
+ project. After taking a moment to install ` busted ` , Lux should show you the following output:
85
87
86
88
``` sh title="lx test"
87
89
●●
You can’t perform that action at this time.
0 commit comments