The complete source code of IdealIRC
http://www.idealirc.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
2.5 KiB
155 lines
2.5 KiB
#include "Script.h"
|
|
#include "Commands.h"
|
|
#include <iostream>
|
|
|
|
/*
|
|
*
|
|
https://github.com/tcbrindle/NanoRange
|
|
|
|
*/
|
|
|
|
|
|
/*
|
|
Finn dypeste
|
|
Bestem operasjonsrekkefølge for hver operatør.
|
|
For hver operatør i stigende rekkefølge:
|
|
For venstre og høyre side:
|
|
Hvis siden allerede er beregnet,
|
|
Bruk resultatet til den operatøren som er tilknyttet med høyeste operasjonsrekkefølge.
|
|
Ellers,
|
|
Bruk siden's verdi.
|
|
Ferdig resultat er i operatøren med høyeste operasjonsrekkefølge.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
- Menus
|
|
- Dialogs
|
|
- Revisit: Command parsing, with functions and arrays
|
|
- Revisit: Arrays, declare like:
|
|
x = []
|
|
x = [value_1, value_2, value3]
|
|
- Functions w/ variadic parameters
|
|
|
|
*/
|
|
|
|
void dispatcher(const std::string& event, std::vector<ValueHolder>& params)
|
|
{
|
|
std::cout << "handle " << event << std::endl;
|
|
}
|
|
|
|
#define T6
|
|
|
|
int main()
|
|
{
|
|
#if defined(T1)
|
|
const std::string scriptdata{R"script(
|
|
function test(a)
|
|
{
|
|
a = 2;
|
|
b = 3;
|
|
|
|
if (a == 1)
|
|
a = 10;
|
|
|
|
else if (a == 2 && b > 1) {
|
|
a = 20;
|
|
if (b == 3) {
|
|
/testere
|
|
}
|
|
}
|
|
|
|
else if (a == 3)
|
|
a = 30;
|
|
|
|
else
|
|
a = 123;
|
|
|
|
return a + " " + b;
|
|
}
|
|
|
|
)script" };
|
|
|
|
#elif defined(T2)
|
|
const std::string scriptdata{R"script(
|
|
function test(a)
|
|
{
|
|
i = 0;
|
|
while (i < 4) {
|
|
if (i == 2) break;
|
|
|
|
/test
|
|
i = i + 1;
|
|
}
|
|
}
|
|
|
|
)script" };
|
|
#elif defined(T3)
|
|
const std::string scriptdata{R"script(
|
|
function test(a)
|
|
{
|
|
i = a / 2;
|
|
/tester
|
|
return i;
|
|
}
|
|
|
|
)script" };
|
|
#elif defined(T4)
|
|
const std::string scriptdata{R"script(
|
|
function test(a)
|
|
{
|
|
i = 0;
|
|
# x = [];
|
|
x[0] = 0;
|
|
while (i < 10) {
|
|
x[i] = i * i;
|
|
i = i + 1;
|
|
}
|
|
|
|
return x[3];
|
|
}
|
|
|
|
)script" };
|
|
#elif defined(T5)
|
|
const std::string scriptdata{R"script(
|
|
|
|
function bbb(a, b, c) {
|
|
return a * b * c;
|
|
}
|
|
|
|
command test(a, b, c, d) /echo tekst: '%a%' '%b%' '%c%' '%d%'
|
|
|
|
function what(x) {
|
|
a = 100 + bbb(4, 4, 2) - 10; # = 122
|
|
/echo %a
|
|
}
|
|
|
|
)script" };
|
|
#elif defined(T6)
|
|
const std::string scriptdata{R"script(
|
|
function what(val)
|
|
{
|
|
dispatch someEvent(1, 2, 3);
|
|
}
|
|
)script" };
|
|
#endif
|
|
|
|
Script scr(scriptdata, &dispatchCommand, &dispatcher);
|
|
|
|
if (scr.reload()) {
|
|
std::vector<ValueHolder> p = { 200 };
|
|
scr.runCommand("test en to");
|
|
|
|
auto val = scr.runFunction("what", p);
|
|
if (val)
|
|
std::cout << "Returned: " << val->toStdString() << std::endl;
|
|
else
|
|
std::cout << "Error " << scr.lastError() << std::endl;
|
|
|
|
}
|
|
else
|
|
std::cout << "Tokenizer error " << scr.lastError() << std::endl;
|
|
|
|
return 0;
|
|
}
|
|
|