Unverified Commit ba99b753 authored by Rob Loach's avatar Rob Loach Committed by GitHub
Browse files

Merge pull request #254 from libretro/dev

0.22.0
parents 334e08af 9e1d2625
......@@ -46,3 +46,6 @@
[submodule "vendor/TinySHA1"]
path = vendor/TinySHA1
url = https://github.com/mohaps/TinySHA1.git
[submodule "vendor/ChaiScript_Extras_Http"]
path = vendor/ChaiScript_Extras_Http
url = https://github.com/RobLoach/ChaiScript_Extras_Http.git
......@@ -4,6 +4,16 @@ 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.22.0 - 2018-05-06
### Features
- `love.filesystem.createDirectory()` to make directories
- `love.filesystem.write()` to write a file in the save directory
- `Http()` to make HTTP requests
### Fixes
- Fix debug build due to undefined "z_error" and "z_verbose" in zlib
- By [@fetzerch](https://github.com/fetzerch) in [#256](https://github.com/libretro/libretro-chailove/pull/256)
## 0.21.0 - 2018-05-02
### Chores
- Switched to [libretro-deps](https://github.com/libretro/libretro-deps) for freetype and zlib
......
......@@ -154,6 +154,11 @@ ifeq ($(HAVE_CHAISCRIPT),)
FLAGS += -DCHAISCRIPT_NO_THREADS -DCHAISCRIPT_NO_THREADS_WARNING -DCHAISCRIPT_NO_DYNLOAD
endif
# ChaiScript Extras Http
ifeq ($(HAVE_CHAISCRIPT),)
FLAGS += -I$(CORE_DIR)/vendor/ChaiScript_Extras_Http/include
endif
# SDL
ifeq ($(platform), win)
SOURCES_C += $(wildcard ./vendor/sdl-libretro/src/*.c ./vendor/sdl-libretro/src/audio/*.c ./vendor/sdl-libretro/src/cdrom/dummy/*.c ./vendor/sdl-libretro/src/cdrom/*.c ./vendor/sdl-libretro/src/cpuinfo/*.c ./vendor/sdl-libretro/src/events/*.c ./vendor/sdl-libretro/src/file/*.c ./vendor/sdl-libretro/src/stdlib/*.c ./vendor/sdl-libretro/src/thread/*.c ./vendor/sdl-libretro/src/timer/*.c ./vendor/sdl-libretro/src/video/*.c ./vendor/sdl-libretro/src/joystick/*.c ./vendor/sdl-libretro/src/video/libretro/*.c ./vendor/sdl-libretro/src/joystick/libretro/*.c ./vendor/sdl-libretro/src/timer/libretro/*.c ./vendor/sdl-libretro/src/audio/libretro/*.c ./vendor/sdl-libretro/src/thread/win32/SDL_sysmutex.c ./vendor/sdl-libretro/src/thread/win32/SDL_syssem.c ./vendor/sdl-libretro/src/thread/win32/SDL_systhread.c ./vendor/sdl-libretro/src/thread/generic/SDL_syscond.c ./vendor/sdl-libretro/src/loadso/dummy/*.c)
......
......@@ -513,10 +513,10 @@ ifeq ($(DEBUG), 1)
CXXFLAGS += -MDd
endif
CFLAGS += -Od -Zi -DDEBUG -D_DEBUG -DZLIB_DEBUG
CFLAGS += -Od -Zi -DDEBUG -D_DEBUG
CXXFLAGS += -Od -Zi -DDEBUG -D_DEBUG
else
CFLAGS += -O0 -g -DDEBUG -DZLIB_DEBUG
CFLAGS += -O0 -g -DDEBUG
CXXFLAGS += -O0 -g -DDEBUG
endif
else
......
#ifndef SRC_CHAILOVEDOCS_HTTP_H_
#define SRC_CHAILOVEDOCS_HTTP_H_
/**
* Allows downloading of files over HTTP (no https).
*
* @code
* var request = Http("http://example.com/index.html")
* while (request.process() == "pending") {
* print("Please Wait...")
* }
* if (request.getStatus() == "failed") {
* print("Failed: " + request.getReasonPhrase())
* }
* global response = request.getResponseString()
* print(response)
* @endcode
*/
class Http {
public:
/**
* Create a Http() object, to request the given URL.
*/
Http(const std::string& url);
/**
* Retrieve the status code.
*/
int getStatusCode();
~Http();
std::string process();
/**
* Retrieve the status code.
*/
std::string getStatus();
/**
* Retrieve the content type.
*/
std::string getContentType();
/**
* Reason why the request failed.
*/
std::string getReasonPhrase();
/**
* Retrieve a string representation of the requested data.
*/
std::string getResponseString();
/**
* Retrieve the size of the response data.
*/
int getResponseSize();
}
#endif
......@@ -287,6 +287,26 @@ FileInfo filesystem::getInfo(const std::string& path) {
return fileInfo;
}
bool filesystem::createDirectory(const std::string& name) {
int ret = PHYSFS_mkdir(name.c_str());
if (ret == 0) {
std::cout << "[ChaiLove] [filesystem] Failed to create directory: " << getLastError() << std::endl;
return false;
}
return true;
}
bool filesystem::write(const std::string& name, const std::string& data) {
PHYSFS_File* file = PHYSFS_openWrite(name.c_str());
if (file == NULL) {
std::cout << "[ChaiLove] [filesystem] Error opening file for writing: " << getLastError() << std::endl;
return false;
}
const char* buffer = data.c_str();
int bytesWritten = PHYSFS_writeBytes(file, (const void*)buffer, data.size());
return bytesWritten >= 0;
}
std::string filesystem::getLastError() {
const char* charErr = PHYSFS_getErrorByCode(PHYSFS_getLastErrorCode());
if (charErr) {
......
......@@ -109,6 +109,27 @@ class filesystem {
*/
bool isSymlink(const std::string& filename);
/**
* Recursively creates a directory in the save directory.
*
* When called with "a/b" it creates both "a" and "a/b", if they don't exist already.
*
* @param name The directory to create.
*
* @return True if the directory was created, false if not.
*/
bool createDirectory(const std::string& name);
/**
* Write data to a file in the save directory. If the file existed already, it will be completely replaced by the new contents.
*
* @param name The name (and path) of the file.
* @param data The string data to write to the file.
*
* @return How many bytes to write.
*/
bool write(const std::string& name, const std::string& data);
/**
* Iterate over the lines in a file, with the given delimiter.
*
......
......@@ -5,6 +5,8 @@
#ifdef __HAVE_CHAISCRIPT__
#include "chaiscript/extras/math.hpp"
using namespace chaiscript;
#define HTTP_IMPLEMENTATION
#include "chaiscript/extras/http.hpp"
#endif
using ::ChaiLove;
......@@ -79,6 +81,9 @@ script::script(const std::string& file) {
chaiscript::bootstrap::standard_library::list_type<std::list<chaiscript::Boxed_Value> >("List", *listModule);
chai.add(listModule);
auto httplib = chaiscript::extras::http::bootstrap();
chai.add(httplib);
// Add the "love" namespace.
chai.register_namespace([](chaiscript::Namespace& love) {
ChaiLove* app = ChaiLove::getInstance();
......@@ -264,8 +269,10 @@ script::script(const std::string& file) {
chai.add(fun(&filesystem::unmount), "unmount");
chai.add(fun(&filesystem::read), "read");
chai.add(fun(&filesystem::isDirectory), "isDirectory");
chai.add(fun(&filesystem::createDirectory), "createDirectory");
chai.add(fun(&filesystem::isSymlink), "isSymlink");
chai.add(fun(&filesystem::isFile), "isFile");
chai.add(fun(&filesystem::write), "write");
chai.add(fun(&filesystem::exists), "exists");
chai.add(fun(&filesystem::getInfo), "getInfo");
chai.add(fun(&filesystem::getDirectoryItems), "getDirectoryItems");
......
/test
/createDirectoryTest
......@@ -43,3 +43,11 @@ assert_equal(theLines[0], "// getDirectoryItems()", "love.filesystem.lines()")
var fileInfo = love.filesystem.getInfo("keyboard.chai")
assert_equal(fileInfo.type, "file", "love.filesystem.getInfo().type")
assert_greater(fileInfo.size, 5, "love.filesystem.getInfo().size")
// createDirectory()
var createDirectoryReturn = love.filesystem.createDirectory("test/createDirectoryTest")
assert(createDirectoryReturn, "love.filesystem.createDirectory()")
// write()
var writeFileReturn = love.filesystem.write("test/createDirectoryTest/test.md", "# Test\n\nHello World!");
assert(writeFileReturn, "love.filesystem.write()")
var request = Http("http://example.com/index.html")
while (request.process() == "pending") {
print("Please Wait...")
}
if (request.getStatus() == "failed") {
print("Failed: " + request.getReasonPhrase())
}
global response = request.getResponseString()
assert_greater(response.find("Example Domain"), 10, "Http()")
......@@ -15,6 +15,7 @@ def load() {
love.filesystem.load("data")
love.filesystem.load("filesystem")
love.filesystem.load("font")
love.filesystem.load("http")
love.filesystem.load("graphics")
love.filesystem.load("image")
love.filesystem.load("list")
......
Subproject commit 56366657470b2559247a5e5e629d8107f62a9474
Subproject commit 61888e164693f58d92b558d402ca67f023e66212
Subproject commit fbc66c7be877ea43c3e0600a336e3f48067d5c00
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