Skip to content

Commit

Permalink
V0.1 is now out
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronnie committed Jan 12, 2016
1 parent 18a1b23 commit c9dd631
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace script
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write you code");
Energy e = new Energy();
try {
e.parse(Console.ReadLine());
}catch(ScriptError se)
{
Console.WriteLine("#Error");
Console.WriteLine(se.Message);
Console.WriteLine("On line [" + se.Posision.Line + "] Row [" + se.Posision.Row + "]");
}

Console.ReadLine();
}
}
}
1 change: 1 addition & 0 deletions plugin/PluginContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public PluginContainer()
container.Add("array", new Array());
container.Add("regex", new Regex());
container.Add("base64", new Base64());
container.Add("time", new Time());
}

public bool exists(string name)
Expand Down
201 changes: 201 additions & 0 deletions plugin/Time.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
using script.builder;
using script.stack;
using script.variabel;
using System;
using System.Globalization;

namespace script.plugin
{
class Time : PluginInterface
{
public void open(VariabelDatabase database)
{
Class time = new Class("Time");

ClassMethods constructor = new ClassMethods(time);
AgumentStack constructorStack = new AgumentStack();

constructorStack.push("int", "year", new NullVariabel());
constructorStack.push("int", "month", new NullVariabel());
constructorStack.push("int", "day", new NullVariabel());
constructorStack.push("int", "hour", new NullVariabel());
constructorStack.push("int", "minut", new NullVariabel());
constructorStack.push("int", "second", new NullVariabel());
constructorStack.push("int", "millisecond", new NullVariabel());

constructor.Aguments = constructorStack;
constructor.caller += Constructor_caller;
constructor.createConstructor();

ClassMethods year = new ClassMethods(time);
year.setName("year");
year.setAccess(true);
year.caller += Year_caller;
year.create();

ClassMethods month = new ClassMethods(time);
month.setName("month");
month.setAccess(true);
month.caller += Month_caller;
month.create();

ClassMethods week = new ClassMethods(time);
week.setName("week");
week.setAccess(true);
week.caller += Week_caller;
week.create();

ClassMethods dayOfWeek = new ClassMethods(time);
dayOfWeek.setName("dayOfWeek");
dayOfWeek.setAccess(true);
dayOfWeek.caller += DayOfWeek_caller;
dayOfWeek.create();

ClassMethods day = new ClassMethods(time);
day.setName("day");
day.setAccess(true);
day.caller += Day_caller;
day.create();

ClassMethods minute = new ClassMethods(time);
minute.setName("minute");
minute.setAccess(true);
minute.caller += Minute_caller;
minute.create();

ClassMethods times = new ClassMethods(time);
times.setName("hour");
times.setAccess(true);
times.caller += Times_caller;
times.create();

ClassMethods second = new ClassMethods(time);
second.setName("second");
second.setAccess(true);
second.caller += Second_caller;
second.create();

ClassMethods millisecond = new ClassMethods(time);
millisecond.setName("millisecond");
millisecond.setAccess(true);
millisecond.caller += Millisecond_caller;
millisecond.create();

database.pushClass(time);
}

private CVar Millisecond_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Millisecond);
}

private CVar Second_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Second);
}

private CVar Times_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Hour);
}

private CVar Minute_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Minute);
}

private CVar Day_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Day);
}

private CVar DayOfWeek_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel((double)((DateTime)obj.systemItems["time"]).DayOfWeek);
}

private CVar Week_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
DateTime dt = (DateTime)obj.systemItems["time"];

DayOfWeek dow = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(dt);

if(dow >= DayOfWeek.Monday && dow <= DayOfWeek.Wednesday)
{
dt = dt.AddDays(3);
}

return new IntVariabel(CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(dt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday));
}

private CVar Month_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Month);
}

private CVar Year_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
return new IntVariabel(((DateTime)obj.systemItems["time"]).Year);
}

private CVar Constructor_caller(ObjectVariabel obj, VariabelDatabase db, CallAgumentStack stack, EnegyData data)
{
DateTime dt = new DateTime();

CVar cache;
int append;

if((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Year;
if(append != 0)
dt = dt.AddYears(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Month;
if (append != 0)
dt = dt.AddMonths(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Day;
if (append != 0)
dt = dt.AddDays(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Hour;
if(append != 0)
dt = dt.AddHours(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Minute;
if(append != 0)
dt = dt.AddMinutes(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Second;
if(append != 0)
dt = dt.AddSeconds(append);
}

if ((cache = stack.pop()) is IntVariabel)
{
append = Convert.ToInt32(cache.toInt(new Posision(0, 0))) - dt.Millisecond;
if(append != 0)
dt = dt.AddMilliseconds(append);
}

obj.systemItems.Add("time", dt);
return new NullVariabel();
}
}
}

0 comments on commit c9dd631

Please sign in to comment.