diff --git a/SMILEBASIC/error.d b/SMILEBASIC/error.d index 872949f..4332e49 100644 --- a/SMILEBASIC/error.d +++ b/SMILEBASIC/error.d @@ -191,6 +191,14 @@ class SubscriptOutOfRange : SmileBasicError super("Subscript out of range(" ~ func ~ ":" ~ arg.to!string ~ ")"); } } +class UsePRGEDITBeforeAnyPRGFunction : SmileBasicError +{ + this(string func) + { + this.errnum = 38; + super("Use PRGEDIT before any PRG function(" ~ func ~ ")"); + } +} class StringTooLong : SmileBasicError { this() diff --git a/SMILEBASIC/program.d b/SMILEBASIC/program.d index c14b578..e085a28 100644 --- a/SMILEBASIC/program.d +++ b/SMILEBASIC/program.d @@ -1,7 +1,9 @@ module otya.smilebasic.program; +import otya.smilebasic.error; import std.range; import std.container; import std.algorithm; +import std.algorithm; struct Slot { @@ -112,6 +114,7 @@ struct Slot class Program { Slot[] slot; + bool PRGEDITused; int currentSlot; int slotSize = 4; this() @@ -124,15 +127,20 @@ class Program } void edit(int slot, int line) { + PRGEDITused = true; this.currentSlot = slot; this.slot[slot].currentLine = line; } wstring get() { + if (!PRGEDITused) + throw new UsePRGEDITBeforeAnyPRGFunction("PRGGET$"); return this.slot[currentSlot].get; } void set(wstring v) { + if (!PRGEDITused) + throw new UsePRGEDITBeforeAnyPRGFunction("PRGSET"); this.slot[currentSlot].set = v; } }