This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generator class | |
class Generator | |
{ | |
var has_value; | |
var value_holder; | |
var params; | |
var func; | |
// empty Generator - no value contained |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var func = fun(){ | |
var ret = 0; | |
for (var i = 0; i < 1000000; ++i) { | |
ret += i; | |
} | |
return ret; | |
} | |
// async takes a 0 parameter function object which is run asynchronously and | |
// returns a Boxed_Value (ie, any value, including void, should work) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
#include <iostream> | |
std::vector<std::vector<std::string>> classic(const int num_vecs, const int vec_size) | |
{ | |
std::vector<std::vector<std::string>> retval; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chrono> | |
#include <string> | |
#include <sstream> | |
#include <vector> | |
#include <iostream> | |
std::string to_string(const int i) | |
{ | |
std::stringstream ss; | |
ss << i; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <chaiscript/chaiscript.hpp> | |
#include <chaiscript/chaiscript_stdlib.hpp> | |
class BaseClass | |
{ | |
public: | |
BaseClass() | |
{ | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <tuple> | |
#include <iostream> | |
#include <typeinfo> | |
template<typename Ret> | |
struct function_type | |
{ | |
}; | |
template<typename Ret> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChaiScript supports the normal kind of control blocks you've come to expect from | |
// C++ and JavaScript | |
if (5 > 2) { | |
print("Yup, 5 > 2"); | |
} else if (2 > 5) { | |
// never gonna happen | |
} else { | |
// really not going to happen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChaiScript's primary error handling is exceptions, just like C++, and uses C++ | |
// exceptions internally. This means that exceptions can be shared / passed / handled | |
// between ChaiScript and C++ | |
// catching chaiscript errors inside of chaiscript | |
try { | |
eval("BLARG") | |
} catch (e) { | |
print("Error while processing eval statement")) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChaiScript supports normal functional programming paradigms, with automatic overload resolution | |
var plus = `+` // get a reference to the function object representing all known `+` functions | |
print(plus("a", "b")) // prints "ab" | |
print(plus(1 , 3)) // prints "4" | |
// print(plus("a" , 3)) // generates a runtime error, no string + int operator available | |
// Back ticks are only necessary for capturing operator functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ChaiScript has its own simple object model and works well with object | |
// oriented C++ | |
// There is no difference between a function and a method, it's just syntactic sugar | |
var s = "mystring".size() // returns 8 | |
var s2 = size("mystring") // returns 8 | |
// class syntax |