Skip to content

Instantly share code, notes, and snippets.

@jerstlouis
Last active March 25, 2017 22:54
Show Gist options
  • Save jerstlouis/b986c2359a415ccf06c4ff53b6f8f3c2 to your computer and use it in GitHub Desktop.
Save jerstlouis/b986c2359a415ccf06c4ff53b6f8f3c2 to your computer and use it in GitHub Desktop.
import "ecere"
class Unit
{
String name;
public property const String name
{
set { delete name; name = CopyString(value); }
get { return name; }
}
~Unit() { delete name; }
}
class Peasant : Unit { }
class King : Unit { }
class Knight : Unit { }
class Dragon : Unit { }
class Game
{
public Container<Unit> units;
~Game()
{
if(units) units.Free();
if(units._class != class(BuiltInContainer)) delete units;
}
}
class App : Application
{
void Main()
{
Game game
{ [
King { name = "Arthur" },
Peasant { name = "Pyp" },
Peasant { name = "Eleanor" },
Dragon { name = "Smaug" }
] };
ECONParser parser { };
File f = FileOpen("units.econ", write);
if(f)
{
WriteECONObject(f, game._class, game, 0);
delete f;
}
delete game;
f = FileOpen("units.econ", read);
if(f)
{
parser.f = f;
parser.GetObject(class(Game), &game);
PrintLn(game);
delete f;
}
delete game;
delete parser;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment