Coder Social home page Coder Social logo

lua_missions's Introduction

Lua Missions

<img src=“https://travis-ci.org/kikito/lua_missions.svg?branch=master” alt=“Build Status” />

The Lua Missions help you learn Lua. The goal is to learn the Lua language, syntax, structure, and some common functions and libraries, through failing tests.

The Structure

The lessons are broken out into areas by file, strings are covered in strings.lua, functions are covered in functions.lua, etc. They are presented in order in the missions.lua file.

Each mission builds up your knowledge of Lua and builds upon itself. It will stop at the first place you need to correct.

Some missions simply need to have the correct answer substituted for an incorrect one. Some, however, require you to supply your own answer. If you see the variable __ (a double underscore) listed, it is a hint to you to supply your own code in order to make it work correctly.

Installing Lua

If you do not have Lua setup, please visit www.lua.org/download.html for operating specific instructions. To check the installations simply type:

*nix platforms from any terminal window:

[~] $ lua -v

Windows from the command prompt (cmd.exe)

c:\lua -v

The output should include the version of Lua that is in your path. These missions are tested in Lua 5.1.x, 5.2.x, Lua 5.3.x, Lua 5.4.x and LuaJIT.

The Missions

In order to run the tests, you must execute the missions.lua file.

*nix platforms, from the lua_missions/missions directory:

[lua_missions] $ cd missions
[lua_missions/missions] $ lua missions.lua

Windows is the same thing

c:\> cd lua_missions\missions
c:\lua_missions\missions\> lua missions.lua

Red, Green, Refactor

In test-driven development the process has always been, red, green, refactor. Write a failing test and run it (red), make the test pass (green), then refactor it (that is look at the code and see if you can make it any better. In this case you will need to run the mission and see it fail (red), make the test pass (green), then take a moment and reflect upon the test and improve the code to better communicate its intent (refactor).

The very first time you run it you will see the following output:

[lua_missions] $ cd missions
[lua_missions/missions] $ lua missions.lua
(in /Users/person/dev/lua_missions)

F

*** Mission status ***

asserts...........................................[Incomplete]
test_assert: [fail]
Assertion failed: Expected [false] to be [true]
The error happened here:
  asserts.lua:3: in function <asserts.lua:2>

It is telling you where to look for the first solution:

Assertion failed: Expected [false] to be [true]
The error happened here:
  asserts.lua:3: in function <asserts.lua:2>

We then open up the asserts.lua file and look at the first test:

function test_assert()
  assert_true(false) -- this should be true
end

We then change the false to true and run the test again. Ignore everything except the method name (test_assert) and the parts inside the method (everything before the end).

In this case the goal is for you to see that if you pass a value to the assert method, it will either ensure it is true and continue on, or fail if in fact the statement is false.

Inspiration

This is heavily inspired by the Ruby Koans project:

rubykoans.com/

Go there and check it out, in case you are curious about ruby. Ruby is a great language and the Ruby Koans are a great way to learn it.

Other Resources

The Lua Language

www.lua.org

Programming in lua

www.lua.org/pil

Lua-users wiki

lua-users.org/

Other stuff

Author

Enrique García <kikito - at - gmail - dot - com>

Source & Issues

www.github.com/kikito/lua_missions

Requires

Lua >= 5.1 (optional: Rake for building up the files from source)

License

lua_missions is released under a Creative Commons, Attribution-NonCommercial-ShareAlike, Version 3.0 (creativecommons.org/licenses/by-nc-sa/3.0/) License.

lua_missions's People

Contributors

dandorman avatar deining avatar kikito avatar ryanberickson avatar schwarz avatar todd1251 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua_missions's Issues

Uses "else if" rather than "elseif" in coroutines.lua

There is an extra space in test_table_coroutine_contains_six_or_seven_elements function in coroutines.lua. This creates an extra if statement which lua expects to be closed, but which is not closed by an "end"-statement.

FIX: either add another "end"-statement to the function or simply remove the space.

Remove rake dependency

Rake was introduced as a "quick and dirty" commodity - Lua missions was inspired by Ruby Koans, so it was easy to just copy the Koans' rakefile and start from there.

Much as I like ruby, I think requiring it just to work with some Lua files is a bit weird. Ideally, if you already have Lua, you shouldn't need anything else to work with the lua-missions (appart from git, if you are making a pr)

The current rakefile has the following tasks:

$ rake -T
rake git:add           # add all the modifications to the git repository, including deletions
rake git:commit        # Commit with a message
rake git:push          # Push to origin
rake git:release       # regenerate missions & push to the git repository
rake missions:delete   # Delete the generated mission files
rake missions:gen      # Generate the Missions from the changed source files
rake missions:regen    # Generate the Missions from the source files from scratch
rake missions:run      # Trying to execute the missions
rake missions:run_src  # Execute the solved missions
  • All the tasks in the git namespace (git:add, etc) can be ignored - most of them can be replaced by 1 or 2 simple git commands.
  • missions:delete is only a "pre-task" used by mission:regen
  • missions:gen is a nice-to-have, but isn't really needed (as long as you have missions:regen)
  • missions:run does literally cd missions; lua missions.lua. And missions:run_src does something similar. I am quite tempted to just ignore them. If not, creating a lua script which executes them is fairly trivial.

So I think only missions:regen is needed. What I am thinking about is a lua script called script/generate.lua, which does what missions:regen currently does:

  • Remove the missions folder and recreate it.
  • For each file inside src:
    • Replace __(<anything>) by __
    • Delete the lines between -- begin skip and -- end skip, both included

This is troublesome for several reasons:

  • Getting a list of files inside a folder isn't possible in vanilla Lua. And I really would want to avoid requiring luarocks and luafilesystem just for this.
  • I am not sure Lua's patters are strong enough to allow easily replacing __(<anything>). In the current rakefile this is done using regular expressions.

The CONTRIBUTING file would have to be updated too, before this issue is closed.

Can't start

I got the following error:

[missions]$ lua missions.lua
lua: ./lib/agent.lua:127: attempt to call global 'setfenv' (a nil value)
stack traceback:
./lib/agent.lua:127: in function 'load_mission'
./lib/agent.lua:212: in function 'run_missions'
missions.lua:29: in main chunk
[C]: in ?

My Lua-version is:
Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio

lua 5.2 env compatability

I'm running Arch and the lua in my path is 5.2.2. When I follow the instructions in the readme file to start the missions,

$ lua missions.lua

I get the following message

lua: ./lib/agent.lua:127: attempt to call global 'setfenv' (a nil value)
stack traceback:
    ./lib/agent.lua:127: in function 'load_mission'
    ./lib/agent.lua:212: in function 'run_missions'
    missions.lua:29: in main chunk
    [C]: in ?

This works fine.

$ lua5.1 missions.lua

It doesn't work at all

Trying to get it work in Ubuntu 22.04 and EndeavourOS (Arch Linux based) I run

$ lua missions.lua

and get

Assertion failed: Expected false to be true
The error happened here:
	asserts.lua:2: in function <asserts.lua:1>
lua5.1: ./lib/agent.lua:153: attempt to concatenate a nil value
stack traceback:
	./lib/agent.lua:153: in function 'mission_print_report'
	./lib/agent.lua:239: in function 'print_report'
	./lib/agent.lua:253: in function 'execute'
	missions.lua:31: in main chunk
	[C]: ?

The same happens with lua 5.2, 5.3 or 5.4

Metatables not explained

I just finished the metatables file, purely from guesswork or cheating from the console.

Metatables are not at all well explained. I'll have to look up a guide elsewhere to have any idea as to what those things are, or their purpose.

Confusing comment

In line 82 of variables.lua, comment states
-- we'll probably not learn about coroutines in our missions.

As far as i can tell coroutines are covered in coroutines.lua, so does this need to be removed?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.