Skip to content

Commit 8b5deb1

Browse files
authored
Merge pull request #1 from nibblebits/dev
New Implementations
2 parents 6e4c4b9 + 0308631 commit 8b5deb1

File tree

7 files changed

+204
-96
lines changed

7 files changed

+204
-96
lines changed

include/config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2323

2424
// Marble versioning information
2525
#define MARBLE_MAJOR_CODENAME "Clearies"
26-
#define MARBLE_VERSION "0.1.5"
26+
#define MARBLE_VERSION "0.2.0"
2727

2828
#define MAX_KEYWORD_SIZE 15
2929
#define MAX_OPERATORS_SIZE 3

src/commonmod/include/commonmod_stringutils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class CommonModule_StringUtils : public Object
4646
static void StringUtils_number_format(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
4747
static void StringUtils_number_to_string(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
4848
static void StringUtils_safe_tags(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
49+
static void StringUtils_strtoupper(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
50+
static void StringUtils_strtolower(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope);
4951

5052
};
5153

src/commonmod/src/commonmod_stringutils.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2626
#include "exceptionobject.h"
2727
#include <iostream>
2828
#include <cmath>
29+
#include <algorithm>
2930

3031
CommonModule_StringUtils::CommonModule_StringUtils(Class *c) : Object(c)
3132
{
@@ -228,6 +229,32 @@ Class *CommonModule_StringUtils::registerClass(ModuleSystem *moduleSystem)
228229
*/
229230
c->registerFunction("safe_tags", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_safe_tags);
230231
moduleSystem->getFunctionSystem()->registerFunction("safe_tags", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_safe_tags);
232+
233+
/**
234+
* @class StringUtils
235+
*
236+
* Converts the given string to upper case and returns it.
237+
*
238+
* Since: V0.2.0
239+
* @works_without_class
240+
*
241+
* function strtoupper(string val) : string
242+
*/
243+
c->registerFunction("strtoupper", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtoupper);
244+
moduleSystem->getFunctionSystem()->registerFunction("strtoupper", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtoupper);
245+
246+
247+
/**
248+
* @class StringUtils
249+
*
250+
* Converts the given string to lower case and returns it
251+
* Since: V0.2.0
252+
* @works_without_class
253+
*
254+
* function strtolower(string val) : string
255+
*/
256+
c->registerFunction("strtolower", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtolower);
257+
moduleSystem->getFunctionSystem()->registerFunction("strtolower", {VarType::fromString("string")}, VarType::fromString("string"), CommonModule_StringUtils::StringUtils_strtolower);
231258
}
232259

233260
void CommonModule_StringUtils::StringUtils_getASCIIString(Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
@@ -376,4 +403,18 @@ void CommonModule_StringUtils::StringUtils_safe_tags(Interpreter *interpreter, s
376403
result = str_replace(result, "<", "&lt;");
377404
result = str_replace(result, ">", "&gt;");
378405
return_value->set(result);
406+
}
407+
408+
void CommonModule_StringUtils::StringUtils_strtoupper(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
409+
{
410+
std::string s = values[0].svalue;
411+
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
412+
return_value->set(s);
413+
}
414+
415+
void CommonModule_StringUtils::StringUtils_strtolower(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
416+
{
417+
std::string s = values[0].svalue;
418+
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
419+
return_value->set(s);
379420
}

src/commonmod/src/storage/commonmod_map.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

2020
#include "commonmod_map.h"
21+
#include "commonmod_value.h"
2122
#include "function.h"
2223
#include "variable.h"
2324
#include "array.h"
@@ -58,6 +59,24 @@ Class* CommonModule_Map::registerClass(ModuleSystem* moduleSystem)
5859
*/
5960
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("Value")}, VarType::fromString("void"), CommonModule_Map::Map_Set);
6061

62+
/**
63+
* @class Map
64+
* function set(string index, number value) : void
65+
*
66+
* Sets the index value represented by the index to the new provided value
67+
*/
68+
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("number")}, VarType::fromString("void"), CommonModule_Map::Map_Set);
69+
70+
/**
71+
* @class Map
72+
* function set(string index, string value) : void
73+
*
74+
* Sets the index value represented by the index to the new provided value
75+
*/
76+
c->registerFunction("set", {VarType::fromString("string"), VarType::fromString("string")}, VarType::fromString("void"), CommonModule_Map::Map_Set);
77+
78+
79+
6180
/**
6281
* @class Map
6382
* function get(string index) : Value
@@ -69,6 +88,16 @@ Class* CommonModule_Map::registerClass(ModuleSystem* moduleSystem)
6988

7089
void CommonModule_Map::Map_Set(Interpreter* interpreter, std::vector<Value> values, Value* return_value, std::shared_ptr<Object> object, Scope* caller_scope)
7190
{
91+
// If our value type is a string or number then we are going to have to create a Value object for it
92+
// and set the Value's value to this string or number
93+
if (values[1].type == VALUE_TYPE_STRING || values[0].type == VALUE_TYPE_NUMBER)
94+
{
95+
std::shared_ptr<CommonModule_Value> new_value =
96+
std::dynamic_pointer_cast<CommonModule_Value>(Object::create(interpreter, interpreter->getClassSystem()->getClassByName("Value"), {values[0]}));
97+
// Overwrite our value passed with the new object Value
98+
values[1] = Value(new_value);
99+
}
100+
72101
std::shared_ptr<CommonModule_Map> map_obj = std::dynamic_pointer_cast<CommonModule_Map>(object);
73102
map_obj->value_map[values[0].svalue] = std::make_unique<Value>(&values[1]);
74103
}

src/commonmod/src/storage/commonmod_vector.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1818
*/
1919

2020
#include "commonmod_vector.h"
21+
#include "commonmod_value.h"
2122
#include "function.h"
2223
#include "variable.h"
2324
#include "array.h"
@@ -62,6 +63,25 @@ Class *CommonModule_Vector::registerClass(ModuleSystem *moduleSystem)
6263
*/
6364
Function *push_function = c->registerFunction("push", {VarType::fromString("Value")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);
6465

66+
/**
67+
* @class Vector
68+
*
69+
* Pushes the number "v" to this Vector
70+
*
71+
* function push(number v) : void
72+
*/
73+
push_function = c->registerFunction("push", {VarType::fromString("number")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);
74+
75+
/**
76+
* @class Vector
77+
*
78+
* Pushes the string "v" to this Vector
79+
*
80+
* function push(string v) : void
81+
*/
82+
push_function = c->registerFunction("push", {VarType::fromString("string")}, VarType::fromString("void"), CommonModule_Vector::Vector_Push);
83+
84+
6585
/**
6686
* @class Vector
6787
*
@@ -112,6 +132,15 @@ Class *CommonModule_Vector::registerClass(ModuleSystem *moduleSystem)
112132
void CommonModule_Vector::Vector_Push(Interpreter *interpreter, std::vector<Value> values, Value *return_value, std::shared_ptr<Object> object, Scope *caller_scope)
113133
{
114134
std::shared_ptr<CommonModule_Vector> vector_obj = std::dynamic_pointer_cast<CommonModule_Vector>(object);
135+
// If our value type is a string or number then we are going to have to create a Value object for it
136+
// and set the Value's value to this string or number
137+
if (values[0].type == VALUE_TYPE_STRING || values[0].type == VALUE_TYPE_NUMBER)
138+
{
139+
std::shared_ptr<CommonModule_Value> new_value =
140+
std::dynamic_pointer_cast<CommonModule_Value>(Object::create(interpreter, interpreter->getClassSystem()->getClassByName("Value"), {values[0]}));
141+
// Overwrite our value passed with the new object Value
142+
values[0] = Value(new_value);
143+
}
115144
values[0].holder = NULL;
116145
vector_obj->vec_values.push_back(Value(&values[0]));
117146
}

0 commit comments

Comments
 (0)