YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Itererating over Classes
robbym
#1 Posted : Thursday, May 26, 2016 10:14:52 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/26/2016(UTC)
Posts: 2

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
Say I have a squirrel script that just contains class definitions. After I compile this file, how would I query the VM to get a list of classes defined in the script?
Mephisto
#2 Posted : Saturday, May 28, 2016 3:17:03 AM(UTC)
Rank: Member

Groups: Registered
Joined: 12/5/2010(UTC)
Posts: 20
Location: Roslindale, MA

Thanks: 9 times
Was thanked: 2 time(s) in 2 post(s)
This is how it's done in SqPlus, but it shouldn't take too much to figure out for Sqrat or raw Squirrel calls

Code:

SquirrelObject sqKey, sqObj, sqRoot = SquirrelVM::GetRootTable();

// Visit all entries in the root table
sqRoot.BeginIteration();
while (sqRoot.Next(sqKey, sqObj))
{
  if (sqObj.GetType() == OT_CLASS)
  {
    std::string strClassName = sqKey.ToString();
    SquirrelObject sqClass = sqObj;

    // Do something with class info
  }
}

1 user thanked Mephisto for this useful post.
robbym on 5/29/2016(UTC)
absence
#3 Posted : Saturday, May 28, 2016 2:18:20 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 8/23/2014(UTC)
Posts: 109
Man
Location: Northern Germany & Lincolnshire, U.K.

Thanks: 1 times
Was thanked: 10 time(s) in 10 post(s)
in squirrel or in C++?
In squirrel you could do something along these lines:

foreach (obj,name in getroottable()) {
if (typeof(obj)=="class") { print(name+" is a class definition:"+obj.tostring()) ; }
}

(again, no guarantees, I'm typing by heart as always :D)
robbym
#4 Posted : Sunday, May 29, 2016 10:08:26 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/26/2016(UTC)
Posts: 2

Thanks: 1 times
Was thanked: 0 time(s) in 0 post(s)
I'm doing it from the rust language, so I'm indirectly using the C API. I understand what I need to do now. Thanks Mephisto.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.106 seconds.