xonecas.io
768
La

learning-ai-lua-code-model / files

learning-ai-lua-code-model / data / raw / tiny_lua_corpus.txt

1008 bytes
1-- Tiny Lua corpus for first language model experiments.
2-- Source: handwritten for this educational repository.
3-- It is intentionally small so the first model can overfit it quickly.
4
5-- In Lua, tables are the main data structure.
6local inventory = {
7  apples = 3,
8  oranges = 5,
9  potions = 2,
10}
11
12local function count_items(items)
13  local total = 0
14
15  for name, amount in pairs(items) do
16    print(name .. ": " .. amount)
17    total = total + amount
18  end
19
20  return total
21end
22
23local total = count_items(inventory)
24
25if total > 5 then
26  print("enough supplies")
27else
28  print("pack more supplies")
29end
30
31-- A tiny object-like table.
32-- The colon syntax passes self as the first argument.
33local player = {}
34player.__index = player
35
36function player.new(name)
37  return setmetatable({ name = name, health = 10 }, player)
38end
39
40function player:heal(amount)
41  self.health = self.health + amount
42  return self.health
43end
44
45local ada = player.new("Ada")
46ada:heal(4)
47print(ada.name .. " has " .. ada.health .. " health")