Skip to content

Commit

Permalink
StackInfos structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sbarisic committed Sep 30, 2015
1 parent d1bd414 commit 2bf65ab
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
9 changes: 9 additions & 0 deletions SqNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ static void Main(string[] args) {
return 0;
});

RegisterFunction(S, "StackInfos", (SS) => {
SQStackInfos SInf;
int Int;
Sq.GetInt(SS, -1, out Int);
Sq.StackInfos(SS, Int, out SInf);
Console.WriteLine("Name: {0}; Line: {1}", SInf.FuncName, SInf.Line);
return 0;
});

Console.WriteLine("Running .NET version of Squirrel {0}\n", String.Join(".", Sq.GetVersion().ToString().ToCharArray()));

while (true) {
Expand Down
10 changes: 4 additions & 6 deletions SqNet/SqNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<ItemGroup>
<Reference Include="SquirrelNET, Version=1.0.5748.35766, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\bin\SquirrelNET.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand All @@ -51,12 +55,6 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SquirrelNET\SquirrelNET\SquirrelNET.vcxproj">
<Project>{98f309a2-9b16-4bad-8620-f8126aea50f7}</Project>
<Name>SquirrelNET</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
10 changes: 6 additions & 4 deletions SquirrelNet/SquirrelNET/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ namespace SquirrelNET {
sq_free(p.ToPointer(), size);
}

SQRESULT Sq::StackInfos(IntPtr v, SQInteger level, IntPtr si) {
tagSQStackInfos* SInf = 0;
auto R = sq_stackinfos(ToVM(v), level, SInf);
si = IntPtr(SInf);
SQRESULT Sq::StackInfos(IntPtr v, SQInteger level, OUT(SQStackInfos) si) {
tagSQStackInfos SInf;
auto R = sq_stackinfos(ToVM(v), level, &SInf);
si.FuncName = PtrToString(SInf.funcname);
si.Source = PtrToString(SInf.source);
si.Line = SInf.line;
return R;
}

Expand Down
9 changes: 8 additions & 1 deletion SquirrelNet/SquirrelNET/SquirrelNET.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ namespace SquirrelNET {
String^ Source;
};

public value class SQStackInfos {
public:
String^ FuncName;
String^ Source;
SQInteger Line;
};

public ref class Sq {
public:
// Implement function pointers as delegates. Use UniString^ instead of String^
Expand Down Expand Up @@ -193,7 +200,7 @@ namespace SquirrelNET {
static IntPtr Malloc(SQUnsignedInteger size);
static IntPtr Realloc(IntPtr p, SQUnsignedInteger oldsize, SQUnsignedInteger newsize);
static void Free(IntPtr p, SQUnsignedInteger size);
static SQRESULT StackInfos(IntPtr v, SQInteger level, IntPtr si);
static SQRESULT StackInfos(IntPtr v, SQInteger level, OUT(SQStackInfos) si);
static void SetDebugHook(IntPtr v);
static void SetNativeDebugHook(IntPtr v, DebugHook^ hook);
};
Expand Down
1 change: 1 addition & 0 deletions SquirrelNet/SquirrelNET/Stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define OUT(Typ) [Out] Typ%
#define ToVM(S) ((HSQUIRRELVM)S.ToPointer())
#define GetSQCharPtr(Str, Name) pin_ptr<const SQChar> Name = PtrToStringChars(Str)
#define PtrToString(Ptr) Marshal::PtrToStringAuto(IntPtr((void*)Ptr))

#define usings\
using namespace System; \
Expand Down

0 comments on commit 2bf65ab

Please sign in to comment.