Version 1.4.0

Tweaked some methods
Working on better thread management
Removed useless methods
Added a pause and resume method (does not work on the main thread)
Added method randomseed(seed)
Invoking internal methods from c# is now supported... May have bugs haven't done much testing yet!
This commit is contained in:
Ryan 2017-09-06 17:06:26 -04:00
parent f8c968cbaa
commit d31c682f30
4 changed files with 81 additions and 45 deletions

View File

@ -72,14 +72,3 @@ namespace parseManagerCS
} }
} }
} }
/*
- New Block structure!
NOTE: If you have an error within the catch block you will not be a happy coder!
```lua
-- This Blcok will catch any errors that take place! This may cause an un recoverable error however!
[BLOCKNAME:event("catch",err)]{
}
```
*/

View File

@ -1,4 +1,4 @@
VERSION 1.2 VERSION 1.3.2
THREAD testthread.txt THREAD testthread.txt
[PLAYGAME]{ [PLAYGAME]{
print("Welcome to my game!") print("Welcome to my game!")
@ -29,9 +29,7 @@ THREAD testthread.txt
snd_select=loadSong("Audio/select.mp3") snd_select=loadSong("Audio/select.mp3")
playSong(bgm_song) playSong(bgm_song)
setFancyForm("left") setFancyForm("left")
str="!" LOAD("savedata.dat")
"Lets do this$str*3$"
LOAD()
write("Name: ") write("Name: ")
name=getInput() name=getInput()
clear() clear()
@ -39,10 +37,10 @@ THREAD testthread.txt
"So your name is $name$, thats cool!" "So your name is $name$, thats cool!"
pos=1 pos=1
sleep(200) sleep(200)
SAVE() SAVE("savedata.dat")
::loop:: ::loop::
clear() clear()
SAVE() SAVE("savedata.dat")
setFG(Color_Blue) setFG(Color_Blue)
fancy(" What to do $name$? Time plsyed $hours_played$:$mins_played$:$secs_played$,/l, Play Game, View Stats, View Credits, Quit Game") fancy(" What to do $name$? Time plsyed $hours_played$:$mins_played$:$secs_played$,/l, Play Game, View Stats, View Credits, Quit Game")
keyUP=isDown("{UP}") keyUP=isDown("{UP}")
@ -52,7 +50,7 @@ THREAD testthread.txt
if keyDOWN==true then setVarPlay("pos",pos+1)|SKIP(0) if keyDOWN==true then setVarPlay("pos",pos+1)|SKIP(0)
if keyENTER==true then GOTO("choicemade")|SKIP(0) if keyENTER==true then GOTO("choicemade")|SKIP(0)
writeAt("->",1,pos+2) writeAt("->",1,pos+2)
sleep(50) sleep(75)
GOTO("loop") GOTO("loop")
::choicemade:: ::choicemade::
playSong(snd_select) playSong(snd_select)
@ -71,6 +69,9 @@ THREAD testthread.txt
if keyENTER==true then SKIP(0)|GOTO("loop") if keyENTER==true then SKIP(0)|GOTO("loop")
print(" ") print(" ")
} }
[testFunc:function(a)]{
"Invoke Test: $a$!"
}
[setVarPlay:function(var,val)]{ [setVarPlay:function(var,val)]{
setVar(var,val) setVar(var,val)
if pos<1 then GOTO("toolittle")|SKIP(0) if pos<1 then GOTO("toolittle")|SKIP(0)

Binary file not shown.

View File

@ -24,10 +24,11 @@ namespace parseManagerCS
/// This also has very flexible flow control meaning you can use it for chat logic and such /// This also has very flexible flow control meaning you can use it for chat logic and such
public class parseManager public class parseManager
{ {
public string _VERSION = "1.3.1"; public string _VERSION = "1.4.0";
standardDefine _invoke = new standardDefine(); standardDefine _invoke = new standardDefine();
string _filepath; string _filepath;
bool _active = true; bool _active = true;
int _pauseRate = 100;
string _define = "NO_DEFINE"; string _define = "NO_DEFINE";
string _entry = "START"; string _entry = "START";
bool _isInternal; bool _isInternal;
@ -39,6 +40,7 @@ namespace parseManagerCS
chunk _currentChunk; chunk _currentChunk;
chunk _lastChunk = null; chunk _lastChunk = null;
ENV _mainENV = new ENV(); ENV _mainENV = new ENV();
bool _paused;
public ENV _defualtENV; public ENV _defualtENV;
Stack<ENV> _fStack = new Stack<ENV>(); Stack<ENV> _fStack = new Stack<ENV>();
Dictionary<string, bool> _flags = new Dictionary<string, bool>(); Dictionary<string, bool> _flags = new Dictionary<string, bool>();
@ -46,7 +48,7 @@ namespace parseManagerCS
Dictionary<string, string> _methods = new Dictionary<string, string>(); Dictionary<string, string> _methods = new Dictionary<string, string>();
void INITENV() void INITENV()
{ {
GLOBALS.SetPM(this); _mainENV.SetSen(GetFlag("casesensitive"));
_mainENV["Color_Black"] = ConsoleColor.Black; _mainENV["Color_Black"] = ConsoleColor.Black;
_mainENV["Color_Blue"] = ConsoleColor.Blue; _mainENV["Color_Blue"] = ConsoleColor.Blue;
_mainENV["Color_Cyan"] = ConsoleColor.Cyan; _mainENV["Color_Cyan"] = ConsoleColor.Cyan;
@ -69,6 +71,14 @@ namespace parseManagerCS
{ {
_mainENV = env; _mainENV = env;
} }
public void Pause()
{
_paused = true;
}
public void Resume()
{
_paused = false;
}
public void makeThread() public void makeThread()
{ {
isThread = true; isThread = true;
@ -163,7 +173,10 @@ namespace parseManagerCS
if (_flags["debugging"]) if (_flags["debugging"])
Console.WriteLine("DEBUGGING: " + msg); Console.WriteLine("DEBUGGING: " + msg);
} }
public void SetPauseRate(int r)
{
_pauseRate = r;
}
void _Parse(string data, string hFile) void _Parse(string data, string hFile)
{ {
foreach (Match m in Regex.Matches(data, @"LOAD ([a-zA-Z0-9_\./]+)")) { foreach (Match m in Regex.Matches(data, @"LOAD ([a-zA-Z0-9_\./]+)")) {
@ -279,6 +292,7 @@ namespace parseManagerCS
var ccN = _currentChunk.GetName(); var ccN = _currentChunk.GetName();
var argsN = c.GetArgs(); var argsN = c.GetArgs();
var fEnv = new ENV(); var fEnv = new ENV();
fEnv.SetSen(GetFlag("casesensitive"));
fEnv.SetParent(_defualtENV); fEnv.SetParent(_defualtENV);
if (!(argsN.Length == 1 && argsN[0] == "")) { if (!(argsN.Length == 1 && argsN[0] == "")) {
for (int i = 0; i < argsN.Length; i++) { for (int i = 0; i < argsN.Length; i++) {
@ -301,6 +315,15 @@ namespace parseManagerCS
return null; return null;
} }
} }
public object Invoke(string method, object[] args)
{
chunk c;
if (isRegisteredFunction(method, out c)) {
return InvokeI(method, args, c, true);
}
PushError("Attempt to invoke a non existing method!");
return null;
}
public object InvokeR(string method, object[] args) public object InvokeR(string method, object[] args)
{ {
chunk c; chunk c;
@ -434,8 +457,13 @@ namespace parseManagerCS
} }
public nextType Next() public nextType Next()
{ {
GLOBALS.SetPM(this);
var tempReturn = new nextType(); var tempReturn = new nextType();
if (_paused) {
if (_pauseRate != 0) {
Thread.Sleep(_pauseRate);
}
return tempReturn;
}
if (_currentChunk == null) { if (_currentChunk == null) {
SetBlock(); SetBlock();
} }
@ -1035,7 +1063,10 @@ namespace parseManagerCS
[Serializable] [Serializable]
public class ENV public class ENV
{ {
bool _sen;
ENV _Parent; ENV _Parent;
bool _busyI;
bool _busyS;
Dictionary<string, object> _vars = new Dictionary<string, object>(); Dictionary<string, object> _vars = new Dictionary<string, object>();
Dictionary<int, object> _varsI = new Dictionary<int, object>(); Dictionary<int, object> _varsI = new Dictionary<int, object>();
public void SetParent(ENV other) public void SetParent(ENV other)
@ -1076,6 +1107,10 @@ namespace parseManagerCS
obj = null; obj = null;
return false; return false;
} }
public void SetSen(bool s)
{
_sen = s;
}
public bool TryGetValue(int ind, out object obj) public bool TryGetValue(int ind, out object obj)
{ {
if (this[ind] != null) { if (this[ind] != null) {
@ -1088,7 +1123,7 @@ namespace parseManagerCS
public object this[string ind] { public object this[string ind] {
get { get {
object obj; object obj;
if (!GLOBALS.GetFlag("casesensitive")) { if (!_sen) {
ind = ind.ToLower(); ind = ind.ToLower();
} }
if (_vars.TryGetValue(ind, out obj)) { if (_vars.TryGetValue(ind, out obj)) {
@ -1100,10 +1135,15 @@ namespace parseManagerCS
return null; return null;
} }
set { set {
if (!GLOBALS.GetFlag("casesensitive")) { while(_busyS){
// wait
}
_busyS=true;
if (!_sen) {
ind = ind.ToLower(); ind = ind.ToLower();
} }
_vars[ind] = value; _vars[ind] = value;
_busyS=false;
} }
} }
public object this[int ind] { public object this[int ind] {
@ -1118,7 +1158,12 @@ namespace parseManagerCS
return null; return null;
} }
set { set {
while(_busyI){
// wait
}
_busyI=true;
_varsI[ind] = value; _varsI[ind] = value;
_busyI=false;
} }
} }
} }
@ -1185,11 +1230,14 @@ namespace parseManagerCS
static class GLOBALS static class GLOBALS
{ {
static standardDefine _define = new standardDefine(); static standardDefine _define = new standardDefine();
static parseManager _current;
static parseManager _main; static parseManager _main;
static readonly ENV _env = new ENV(); static readonly ENV _env = new ENV();
static List<string> _numvars = new List<string>(); static List<string> _numvars = new List<string>();
static List<parseManager> _Threads = new List<parseManager>(); static List<parseManager> _Threads = new List<parseManager>();
public static parseManager[] GetThreads()
{
return _Threads.ToArray();
}
public static void AddThread(parseManager PM) public static void AddThread(parseManager PM)
{ {
_Threads.Add(PM); _Threads.Add(PM);
@ -1229,27 +1277,14 @@ namespace parseManagerCS
{ {
_env[ind] = data; _env[ind] = data;
} }
public static void SetPM(parseManager o)
{
_current = o;
}
public static void SetMainPM(parseManager o) public static void SetMainPM(parseManager o)
{ {
_main = o; _main = o;
} }
public static parseManager GetPM()
{
return _current;
}
public static parseManager GetMainPM() public static parseManager GetMainPM()
{ {
return _main; return _main;
} }
public static bool GetFlag(string flag)
{
var PM = GetPM();
return PM.GetFlag(flag);
}
public static void Add_Var(string var) public static void Add_Var(string var)
{ {
if (!_numvars.Contains(var)) { if (!_numvars.Contains(var)) {
@ -1373,7 +1408,7 @@ public class standardDefine
next = PM.Next(); next = PM.Next();
} }
} }
public void SAVE(parseManager PM) public void SAVE(parseManager PM, string name)
{ {
if (PM.isAThread()) { if (PM.isAThread()) {
GLOBALS.GetMainPM().PushError("Cannot Call SAVE() in a thread!"); GLOBALS.GetMainPM().PushError("Cannot Call SAVE() in a thread!");
@ -1383,15 +1418,15 @@ public class standardDefine
env["__CurrentChunkName"] = c.GetName(); env["__CurrentChunkName"] = c.GetName();
env["__CurrentChunkPos"] = c.GetPos(); env["__CurrentChunkPos"] = c.GetPos();
env["__DefualtENV"] = PM.GetENV(); env["__DefualtENV"] = PM.GetENV();
GLOBALS.WriteToBinaryFile("savedata.dat", env); GLOBALS.WriteToBinaryFile(name, env);
} }
public bool LOAD(parseManager PM) public bool LOAD(parseManager PM, string _name)
{ {
if (PM.isAThread()) { if (PM.isAThread()) {
GLOBALS.GetMainPM().PushError("Cannot Call LOAD() in a thread!"); GLOBALS.GetMainPM().PushError("Cannot Call LOAD() in a thread!");
} }
try { try {
ENV env = GLOBALS.ReadFromBinaryFile("savedata.dat"); ENV env = GLOBALS.ReadFromBinaryFile(_name);
var name = (string)env["__CurrentChunkName"]; var name = (string)env["__CurrentChunkName"];
var pos = (int)env["__CurrentChunkPos"]; var pos = (int)env["__CurrentChunkPos"];
var denv = (ENV)env["__DefualtENV"]; var denv = (ENV)env["__DefualtENV"];
@ -1558,7 +1593,15 @@ public class standardDefine
} }
public void pause(parseManager PM) public void pause(parseManager PM)
{ {
Console.ReadLine(); if (!PM.isAThread()) {
PM.Pause();
} else {
PM.debug("WARNING: Calling pause with the main thread is not allowed!");
}
}
public void resume(parseManager PM)
{
PM.Resume();
} }
public void print(parseManager PM, object o) public void print(parseManager PM, object o)
{ {
@ -1572,6 +1615,9 @@ public class standardDefine
{ {
return rnd.NextDouble(); return rnd.NextDouble();
} }
public void randomseed(parseManager PM,double seed){
rnd = new Random((int)seed);
}
public double round(parseManager PM, double num, double n) public double round(parseManager PM, double num, double n)
{ {
return Math.Round(num, (int)n); return Math.Round(num, (int)n);