Skip to content

Commit 11cfa9e

Browse files
committed
Readme for examples folder.
1 parent 75a36eb commit 11cfa9e

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed

examples/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Examples
2+
3+
`*.lua2p` files are the unprocessed source files.
4+
`*.output.lua` files show the processed output / final program.
5+
6+
| File | Description
7+
| ---- | -----------
8+
| [dualCode.lua2p](dualCode.lua2p) | Shows how you can declare variables in the metaprogram and final program at the same time. (`!!x=y`)
9+
| [macros.lua2p](macros.lua2p) | Shows how macros can be used to enhance code. (`@insert func()`)
10+
| [namedConstants.lua2p](namedConstants.lua2p) | Shows how you can use variables in the metaprogram to output literals into the final program. (`!()`)
11+
| [optimizeDataAccess.lua2p](optimizeDataAccess.lua2p) | Shows how you could make data access in the final program more efficient.
12+
| [parseFile.lua2p](parseFile.lua2p) | Shows how you can perform a computationally expensive operation at build time instead of every time at runtime.
13+
| [selectiveFunctionality.lua2p](selectiveFunctionality.lua2p) | Shows how parts of the code can be excluded from the final program using variables in the metaprogram.

examples/dualCode.output.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
-- Assignments starting with !! will appear in both the metaprogram and the final output.
1111
local TEXT_HEIGHT = 30
12+
1213
local BUTTON_PADDING = 15
1314
local BUTTON_BORDER = 2
15+
1416
local BUTTON_WIDTH = 400
1517
local BUTTON_HEIGHT = 64
1618

examples/macros.lua2p

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,7 @@ assert(i > 1 and i < 7, "Invalid index. It must be 1<=i<=7 but is "..i)
4343
-- itself in the message.
4444
@insert assert(i > 1 and i < 7)
4545

46+
-- Note that @insert can also be written as @@.
47+
@@assert(i > 1 and i < 7)
48+
4649
print("'i' is all good!")

examples/macros.output.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,7 @@ if not (i > 1 and i < 7) then error("Invalid index. It must be 1<=i<=7 but is "
2828
-- itself in the message.
2929
if not (i > 1 and i < 7) then error("Assertion failed: i > 1 and i < 7") end
3030

31+
-- Note that @insert can also be written as @@.
32+
if not (i > 1 and i < 7) then error("Assertion failed: i > 1 and i < 7") end
33+
3134
print("'i' is all good!")

examples/optimizeDataAccess.lua2p

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ CHARACTERS_UNLOCKED_BY_DEFAULT = {
5151
!end
5252
}
5353

54+
--
5455
-- Instead of iterating over the CHARACTERS array until we find
5556
-- the character with the specified ID, we use the maps above to
5657
-- get the information we want through a single table lookup.
58+
--
5759
function getCharacterName(charId)
5860
return CHARACTER_NAMES[charId]
5961
end

examples/optimizeDataAccess.output.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ CHARACTERS_UNLOCKED_BY_DEFAULT = {
4545
dev = true,
4646
}
4747

48+
--
4849
-- Instead of iterating over the CHARACTERS array until we find
4950
-- the character with the specified ID, we use the maps above to
5051
-- get the information we want through a single table lookup.
52+
--
5153
function getCharacterName(charId)
5254
return CHARACTER_NAMES[charId]
5355
end

0 commit comments

Comments
 (0)