Skip to content

Commit

Permalink
Merge pull request #1 from nibblebits/dev
Browse files Browse the repository at this point in the history
New Implementations
  • Loading branch information
nibblebits authored Sep 19, 2018
2 parents 6e4c4b9 + 0308631 commit 8b5deb1
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 96 deletions.
2 changes: 1 addition & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

// Marble versioning information
#define MARBLE_MAJOR_CODENAME "Clearies"
#define MARBLE_VERSION "0.1.5"
#define MARBLE_VERSION "0.2.0"

#define MAX_KEYWORD_SIZE 15
#define MAX_OPERATORS_SIZE 3
Expand Down
2 changes: 2 additions & 0 deletions src/commonmod/include/commonmod_stringutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CommonModule_StringUtils : public Object
static void StringUtils_number_format(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
static void StringUtils_number_to_string(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
static void StringUtils_safe_tags(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
static void StringUtils_strtoupper(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
static void StringUtils_strtolower(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);

};

Expand Down
41 changes: 41 additions & 0 deletions src/commonmod/src/commonmod_stringutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "exceptionobject.h"
#include <iostream>
#include <cmath>
#include <algorithm>

CommonModule_StringUtils::CommonModule_StringUtils(Class *c) : Object(c)
{
Expand Down Expand Up @@ -228,6 +229,32 @@ Class *CommonModule_StringUtils::registerClass(ModuleSystem *moduleSystem)
*/
c->registerFunction("safe_tags", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_safe_tags);
moduleSystem->getFunctionSystem()->registerFunction("safe_tags", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_safe_tags);

/**
* @class StringUtils
*
* Converts the given string to upper case and returns it.
*
* Since: V0.2.0
* @works_without_class
*
* function strtoupper(string val) : string
*/
c->registerFunction("strtoupper", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtoupper);
moduleSystem->getFunctionSystem()->registerFunction("strtoupper", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtoupper);


/**
* @class StringUtils
*
* Converts the given string to lower case and returns it
* Since: V0.2.0
* @works_without_class
*
* function strtolower(string val) : string
*/
c->registerFunction("strtolower", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtolower);
moduleSystem->getFunctionSystem()->registerFunction("strtolower", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtolower);
}

void CommonModule_StringUtils::StringUtils_getASCIIString(Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
Expand Down Expand Up @@ -376,4 +403,18 @@ void CommonModule_StringUtils::StringUtils_safe_tags(Interpreter *interpreter, s
result = str_replace(result, "<", "&lt;");
result = str_replace(result, ">", "&gt;");
return_value->set(result);
}

void CommonModule_StringUtils::StringUtils_strtoupper(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
{
std::string s = values[0].svalue;
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
return_value->set(s);
}

void CommonModule_StringUtils::StringUtils_strtolower(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
{
std::string s = values[0].svalue;
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return_value->set(s);
}
29 changes: 29 additions & 0 deletions src/commonmod/src/storage/commonmod_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "commonmod_map.h"
#include "commonmod_value.h"
#include "function.h"
#include "variable.h"
#include "array.h"
Expand Down Expand Up @@ -58,6 +59,24 @@ Class* CommonModule_Map::registerClass(ModuleSystem* moduleSystem)
*/
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("Value")}, VarType::fromString("void"), CommonModule_Map::Map_Set);

/**
* @class Map
* function set(string index, number value) : void
*
* Sets the index value represented by the index to the new provided value
*/
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("number")}, VarType::fromString("void"), CommonModule_Map::Map_Set);

/**
* @class Map
* function set(string index, string value) : void
*
* Sets the index value represented by the index to the new provided value
*/
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("string")}, VarType::fromString("void"), CommonModule_Map::Map_Set);



/**
* @class Map
* function get(string index) : Value
Expand All @@ -69,6 +88,16 @@ Class* CommonModule_Map::registerClass(ModuleSystem* moduleSystem)

void CommonModule_Map::Map_Set(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
{
// If our value type is a string or number then we are going to have to create a Value object for it
// and set the Value's value to this string or number
if (values[1].type == VALUE_TYPE_STRING || values[0].type == VALUE_TYPE_NUMBER)
{
std::shared_ptr<CommonModule_Value> new_value =
std::dynamic_pointer_cast<CommonModule_Value>(Object::create(interpreter, interpreter->getClassSystem()->getClassByName("Value"), {values[0]}));
// Overwrite our value passed with the new object Value
values[1] = Value(new_value);
}

std::shared_ptr<CommonModule_Map> map_obj = std::dynamic_pointer_cast<CommonModule_Map>(object);
map_obj->value_map[values[0].svalue] = std::make_unique<Value>(&values[1]);
}
Expand Down
29 changes: 29 additions & 0 deletions src/commonmod/src/storage/commonmod_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "commonmod_vector.h"
#include "commonmod_value.h"
#include "function.h"
#include "variable.h"
#include "array.h"
Expand Down Expand Up @@ -62,6 +63,25 @@ Class *CommonModule_Vector::registerClass(ModuleSystem *moduleSystem)
*/
Function *push_function = c->registerFunction("push", {VarType::fromString("Value")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);

/**
* @class Vector
*
* Pushes the number "v" to this Vector
*
* function push(number v) : void
*/
push_function = c->registerFunction("push", {VarType::fromString("number")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);

/**
* @class Vector
*
* Pushes the string "v" to this Vector
*
* function push(string v) : void
*/
push_function = c->registerFunction("push", {VarType::fromString("string")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);


/**
* @class Vector
*
Expand Down Expand Up @@ -112,6 +132,15 @@ Class *CommonModule_Vector::registerClass(ModuleSystem *moduleSystem)
void CommonModule_Vector::Vector_Push(Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
{
std::shared_ptr<CommonModule_Vector> vector_obj = std::dynamic_pointer_cast<CommonModule_Vector>(object);
// If our value type is a string or number then we are going to have to create a Value object for it
// and set the Value's value to this string or number
if (values[0].type == VALUE_TYPE_STRING || values[0].type == VALUE_TYPE_NUMBER)
{
std::shared_ptr<CommonModule_Value> new_value =
std::dynamic_pointer_cast<CommonModule_Value>(Object::create(interpreter, interpreter->getClassSystem()->getClassByName("Value"), {values[0]}));
// Overwrite our value passed with the new object Value
values[0] = Value(new_value);
}
values[0].holder = NULL;
vector_obj->vec_values.push_back(Value(&values[0]));
}
Expand Down
Loading

0 comments on commit 8b5deb1

Please sign in to comment.