Verified Commit 73b0ff9f authored by RobLoach's avatar RobLoach
Browse files

Add List()

parent c2bfa1ab
......@@ -4,6 +4,10 @@ All notable changes to [ChaiLove](https://github.com/RobLoach/ChaiLove) will be
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## 0.16.1 - Unrealeased
### Added
- `List()` for linked list
## 0.16.0 - 2018-03-05
### Fixed
- Fix undefined zlib symbols in debug build
......
......@@ -361,7 +361,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
INPUT = src examples # README.md
INPUT = src examples test # README.md
#USE_MDFILE_AS_MAINPAGE = README.md
# If the value of the INPUT tag contains directories, you can use the
......
/**
* ChaiLove API Documentation
*
* This file is used to add various API docs for classes.
*/
#ifndef SRC_CHAILOVEDOCS_H_
#define SRC_CHAILOVEDOCS_H_
/**
* @brief Linked List
*
* Provides a linked list data structure.
*/
class List {
public:
/**
* Construct a list.
*/
List();
/**
* @brief Insert element at beginning.
*/
void push_front(void* val);
/**
* @brief Add element at the end.
*/
void push_back(void* val);
/**
* @brief Retrieves the size of the list.
*/
void size();
/**
* @brief Change size.
*/
void resize(int size);
/**
* @brief Delete first element.
*/
void pop_front();
/**
* @brief Delete last element.
*/
void pop_back();
};
#endif // SRC_CHAILOVEDOCS_H_
......@@ -66,6 +66,11 @@ script::script(const std::string& file) {
chai.add(bootstrap::standard_library::vector_type<std::vector<std::string>>("StringVector"));
chai.add(bootstrap::standard_library::map_type<std::map<std::string, bool>>("StringBoolMap"));
// List
auto listModule = std::make_shared<chaiscript::Module>();
chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List", *listModule);
chai.add(listModule);
// Add the "love" namespace.
chai.register_namespace([](chaiscript::Namespace& love) {
ChaiLove* app = ChaiLove::getInstance();
......
var list = List()
list.push_back(3)
list.push_back("A")
assert_equal(list.front(), 3, "List.front()")
assert_equal(list.back(), "A", "List.back()")
assert_equal(list.size(), 2, "List.size()")
list.resize(0);
assert_equal(list.size(), 0, "List.resize()");
var finalListItem = "This will loop through all items, and assign the last"
list.push_back("first")
list.push_back("second")
list.push_back("third")
for (listItem : list) {
finalListItem = listItem
}
assert_equal(finalListItem, "third", "List.for()")
list.pop_front()
assert_equal(list.front(), "second", "List.pop_front()")
......@@ -10,6 +10,7 @@ def load() {
love.filesystem.load("font")
love.filesystem.load("graphics")
love.filesystem.load("image")
love.filesystem.load("list")
love.filesystem.load("math")
love.filesystem.load("mouse")
love.filesystem.load("joystick")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment