1
0

Removed Squirrel.

This compiles under Windows, but is untested in Linux.
This commit is contained in:
madmaxoft
2013-08-07 22:39:40 +02:00
parent 3d027a8928
commit 09ebda4d10
93 changed files with 1 additions and 23177 deletions

View File

@@ -1,4 +1,3 @@
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual C++ Express 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MCServer", "MCServer.vcproj", "{32012054-0C96-4C43-AB27-174FF8E72D66}"
@@ -22,8 +21,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ToLua", "ToLua.vcproj", "{E
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebServer", "WebServer.vcproj", "{9A476537-42C0-4848-AB40-15CFE83D17A8}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Squirrel3", "Squirrel3.vcproj", "{54DBF6CE-D1A8-4CCB-A249-4BF1CA9B7E4C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CryptoPP", "CryptoPP.vcproj", "{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "expat", "expat.vcproj", "{5FCFAF8D-FF2C-456D-A72C-1D76F913AD96}"
@@ -71,9 +68,6 @@ Global
{9A476537-42C0-4848-AB40-15CFE83D17A8}.Release profiled|Win32.Build.0 = Release profiled|Win32
{9A476537-42C0-4848-AB40-15CFE83D17A8}.Release|Win32.ActiveCfg = Release|Win32
{9A476537-42C0-4848-AB40-15CFE83D17A8}.Release|Win32.Build.0 = Release|Win32
{54DBF6CE-D1A8-4CCB-A249-4BF1CA9B7E4C}.Debug|Win32.ActiveCfg = Debug|Win32
{54DBF6CE-D1A8-4CCB-A249-4BF1CA9B7E4C}.Release profiled|Win32.ActiveCfg = Release profiled|Win32
{54DBF6CE-D1A8-4CCB-A249-4BF1CA9B7E4C}.Release|Win32.ActiveCfg = Release|Win32
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Debug|Win32.ActiveCfg = Debug|Win32
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Debug|Win32.Build.0 = Debug|Win32
{3423EC9A-52E4-4A4D-9753-EDEBC38785EF}.Release profiled|Win32.ActiveCfg = Release|Win32

View File

@@ -1537,14 +1537,6 @@
RelativePath="..\source\Plugin_NewLua.h"
>
</File>
<File
RelativePath="..\source\Plugin_Squirrel.cpp"
>
</File>
<File
RelativePath="..\source\Plugin_Squirrel.h"
>
</File>
<File
RelativePath="..\source\PluginManager.cpp"
>
@@ -1553,14 +1545,6 @@
RelativePath="..\source\PluginManager.h"
>
</File>
<File
RelativePath="..\source\SquirrelCommandBinder.cpp"
>
</File>
<File
RelativePath="..\source\SquirrelCommandBinder.h"
>
</File>
<File
RelativePath="..\source\StringMap.cpp"
>
@@ -1585,38 +1569,6 @@
RelativePath="..\source\WebPlugin.h"
>
</File>
<Filter
Name="Squirrel"
>
<File
RelativePath="..\source\squirrelbindings\SquirrelArray.h"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelBaseClass.h"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelBindings.cpp"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelBindings.h"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelFunctions.cpp"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelFunctions.h"
>
</File>
<File
RelativePath="..\source\squirrelbindings\SquirrelObject.h"
>
</File>
</Filter>
</Filter>
<Filter
Name="External"

View File

@@ -1,109 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="Squirrel3" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug Win32">
<Option output="lib" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="Debug Win32/Squirrel3" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-DWIN32" />
<Add option="-D_DEBUG" />
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
<Add option="-W" />
<Add option="-O0" />
<Add directory="../squirrel_3_0_1_stable/include" />
</Compiler>
<ResourceCompiler>
<Add directory="../squirrel_3_0_1_stable/include" />
</ResourceCompiler>
</Target>
<Target title="Release Win32">
<Option output="lib" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="Release Win32/Squirrel3" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-DWIN32" />
<Add option="-DNDEBUG" />
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
<Add option="-W" />
<Add directory="../squirrel_3_0_1_stable/include" />
</Compiler>
<ResourceCompiler>
<Add directory="../squirrel_3_0_1_stable/include" />
</ResourceCompiler>
</Target>
<Target title="Release profiled Win32">
<Option output="lib" prefix_auto="1" extension_auto="1" />
<Option working_dir="" />
<Option object_output="Release profiled Win32/Squirrel3" />
<Option type="2" />
<Option compiler="gcc" />
<Option createDefFile="1" />
<Compiler>
<Add option="-DWIN32" />
<Add option="-DNDEBUG" />
<Add option="-D_CRT_SECURE_NO_WARNINGS" />
<Add option="-W" />
<Add directory="../squirrel_3_0_1_stable/include" />
</Compiler>
<ResourceCompiler>
<Add directory="../squirrel_3_0_1_stable/include" />
</ResourceCompiler>
</Target>
</Build>
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdaux.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdblob.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdblobimpl.h" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdio.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdmath.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdrex.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdstream.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdstream.h" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdstring.cpp" />
<Unit filename="../squirrel_3_0_1_stable/sqstdlib/sqstdsystem.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqapi.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqarray.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqbaselib.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqclass.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqclass.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqclosure.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqcompiler.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqcompiler.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqdebug.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqfuncproto.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqfuncstate.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqfuncstate.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqlexer.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqlexer.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqmem.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqobject.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqobject.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqopcodes.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqpcheader.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqstate.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqstate.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqstring.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqtable.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqtable.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/squserdata.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/squtils.h" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqvm.cpp" />
<Unit filename="../squirrel_3_0_1_stable/squirrel/sqvm.h" />
<Extensions>
<code_completion />
<envvars />
<debugger />
</Extensions>
</Project>
</CodeBlocks_project_file>

View File

@@ -1,384 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="Squirrel3"
ProjectGUID="{54DBF6CE-D1A8-4CCB-A249-4BF1CA9B7E4C}"
RootNamespace="Squirrel3"
Keyword="ManagedCProj"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\Squirrel3"
IntermediateDirectory="$(ConfigurationName)\Squirrel3"
ConfigurationType="4"
CharacterSet="0"
ManagedExtensions="0"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\squirrel_3_0_1_stable\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="1"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\Squirrel3"
IntermediateDirectory="$(ConfigurationName)\Squirrel3"
ConfigurationType="4"
CharacterSet="0"
ManagedExtensions="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../squirrel_3_0_1_stable/include"
PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release profiled|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)\Squirrel3"
IntermediateDirectory="$(ConfigurationName)\Squirrel3"
ConfigurationType="4"
CharacterSet="0"
ManagedExtensions="0"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="../squirrel_3_0_1_stable/include"
PreprocessorDefinitions="WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS"
RuntimeLibrary="0"
UsePrecompiledHeader="0"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLibrarianTool"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
<AssemblyReference
RelativePath="System.dll"
AssemblyName="System, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.Data.dll"
AssemblyName="System.Data, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=x86"
MinFrameworkVersion="131072"
/>
<AssemblyReference
RelativePath="System.XML.dll"
AssemblyName="System.Xml, Version=2.0.0.0, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL"
MinFrameworkVersion="131072"
/>
</References>
<Files>
<Filter
Name="sqstdlib"
>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdaux.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdblob.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdblobimpl.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdio.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdmath.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdrex.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdstream.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdstream.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdstring.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\sqstdlib\sqstdsystem.cpp"
>
</File>
</Filter>
<Filter
Name="squirrel"
>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqapi.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqarray.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqbaselib.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqclass.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqclass.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqclosure.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqcompiler.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqcompiler.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqdebug.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqfuncproto.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqfuncstate.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqfuncstate.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqlexer.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqlexer.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqmem.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqobject.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqobject.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqopcodes.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqpcheader.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqstate.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqstate.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqstring.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqtable.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqtable.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\squserdata.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\squtils.h"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqvm.cpp"
>
</File>
<File
RelativePath="..\squirrel_3_0_1_stable\squirrel\sqvm.h"
>
</File>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@@ -131,12 +131,6 @@ typedef unsigned short UInt16;
#endif
#endif
#if !defined(ANDROID_NDK)
// 2012_11_08 _X: Disabled SquirrelVM, because it would crash the server from time to time.
// For details see: http://forum.mc-server.org/showthread.php?tid=610
// #define USE_SQUIRREL
#endif
#if defined(ANDROID_NDK)
#define FILE_IO_PREFIX "/sdcard/mcserver/"
#else

View File

@@ -127,7 +127,7 @@ public:
{
E_CPP,
E_LUA,
E_SQUIRREL,
E_SQUIRREL, // OBSOLETE, but kept in place to remind us of the horrors lurking in the history
};
PluginLanguage GetLanguage() { return m_Language; }
void SetLanguage( PluginLanguage a_Language ) { m_Language = a_Language; }

View File

@@ -1073,7 +1073,6 @@ void cPluginManager::UnloadPluginsNow()
m_Commands.clear();
m_ConsoleCommands.clear();
//SquirrelVM::Shutdown(); // This breaks shit
}

View File

@@ -1,409 +0,0 @@
#include "Globals.h"
#ifdef USE_SUIRREL
#include "Plugin_Squirrel.h"
#include "squirrelbindings/SquirrelFunctions.h"
#include "squirrelbindings/SquirrelBindings.h"
#include "squirrelbindings/SquirrelBaseClass.h"
cPlugin_Squirrel::cPlugin_Squirrel( const char* a_PluginName )
: cPlugin( a_PluginName )
{
SetLanguage( cPlugin::E_SQUIRREL );
m_PluginName = a_PluginName;
}
cPlugin_Squirrel::~cPlugin_Squirrel()
{
delete m_Plugin;
}
bool cPlugin_Squirrel::Initialize()
{
cCSLock Lock(m_CriticalSection);
std::string PluginPath = std::string("Plugins/") + m_PluginName + ".nut";
Sqrat::Script script;
script.CompileFile(PluginPath);
if(script.IsNull())
{
LOGERROR("Unable to run script \"%s\"", m_PluginName);
}
try {
script.Run();
Sqrat::Function construct(Sqrat::RootTable(), m_PluginName);
if(construct.IsNull())
{
LOGERROR("Constructor for Plugin \"%s\" not found.", m_PluginName);
return false;
}
Sqrat::Object obj = construct.Evaluate<Sqrat::Object>();
((cSquirrelBaseClass *) obj.GetInstanceUP())->setInstance(this);
m_Plugin = new SquirrelObject(obj);
Sqrat::Object PluginName = obj.GetSlot("name");
if(!PluginName.IsNull())
{
this->SetName(PluginName.Cast<const char*>());
}
Sqrat::Function init = m_Plugin->GetFunction("Initialize");
if(init.IsNull())
{
LOGERROR("Can not initialize plugin \"%s\"", m_PluginName);
return false;
}
return init.Evaluate<bool>();
} catch(Sqrat::Exception &e)
{
LOGERROR("Initialisation of \"%s\" failed: %s", m_PluginName, e.Message().c_str());
return false;
}
}
void cPlugin_Squirrel::OnDisable()
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnDisable")) return;
m_Plugin->GetFunction("OnDisable").Execute();
}
void cPlugin_Squirrel::Tick(float a_Dt)
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnTick")) return;
m_Plugin->GetFunction("OnTick").Execute(a_Dt);
}
bool cPlugin_Squirrel::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup)
{
cCSLock Lock(m_CriticalSection);
if (!m_Plugin->HasFunction("OnCollectPickup"))
{
return false;
}
return m_Plugin->GetFunction("OnCollectPickup").Evaluate<bool>(a_Player, a_Pickup);
}
bool cPlugin_Squirrel::OnDisconnect(cPlayer* a_Player, const AString & a_Reason)
{
cCSLock Lock( m_CriticalSection );
if (!m_Plugin->HasFunction("OnDisconnect")) return false;
return m_Plugin->GetFunction("OnDisconnect").Evaluate<bool>(a_Player, a_Reason);
}
bool cPlugin_Squirrel::OnBlockPlace(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem)
{
cCSLock Lock(m_CriticalSection);
if (!m_Plugin->HasFunction("OnBlockPlace")) return false;
return m_Plugin->GetFunction("OnBlockPlace").Evaluate<bool>(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_HeldItem);
}
bool cPlugin_Squirrel::OnBlockDig(cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta)
{
cCSLock Lock(m_CriticalSection);
if (!m_Plugin->HasFunction("OnBlockDig")) return false;
return m_Plugin->GetFunction("OnBlockDig").Evaluate<bool>(a_Player, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_Status, a_OldBlock, a_OldMeta);
}
bool cPlugin_Squirrel::OnChat(cPlayer * a_Player, const AString & a_Message)
{
cCSLock Lock(m_CriticalSection);
if (!m_Plugin->HasFunction("OnChat")) return false;
return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Player, a_Message);
}
bool cPlugin_Squirrel::OnLogin(cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username)
{
cCSLock Lock( m_CriticalSection );
if (!m_Plugin->HasFunction("OnLogin"))
{
return false;
}
return m_Plugin->GetFunction("OnLogin").Evaluate<bool>(a_Client, a_ProtocolVersion, a_Username);
}
void cPlugin_Squirrel::OnPlayerSpawn( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnPlayerSpawn")) return;
return m_Plugin->GetFunction("OnPlayerSpawn").Execute(a_Player);
}
bool cPlugin_Squirrel::OnPlayerJoin( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnPlayerJoin")) return false;
return m_Plugin->GetFunction("OnPlayerJoin").Evaluate<bool>(a_Player);
}
void cPlugin_Squirrel::OnPlayerMove( cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnPlayerMove")) return;
return m_Plugin->GetFunction("OnPlayerMove").Execute(a_Player);
}
void cPlugin_Squirrel::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo )
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnTakeDamage")) return;
return m_Plugin->GetFunction("OnTakeDamage")(a_Pawn, a_TakeDamageInfo);
}
bool cPlugin_Squirrel::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
{
cCSLock Lock( m_CriticalSection );
if(!m_Plugin->HasFunction("OnKilled")) return false;
return m_Plugin->GetFunction("OnKilled").Evaluate<bool>(a_Killed, a_Killer);
}
void cPlugin_Squirrel::OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnChunkGenerated")) return;
return m_Plugin->GetFunction("OnChunkGenerated")(a_World, a_ChunkX, a_ChunkZ);
}
bool cPlugin_Squirrel::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_pLuaChunk)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnChunkGenerating")) return false;
return m_Plugin->GetFunction("OnChunkGenerating").Evaluate<bool>(a_World, a_ChunkX, a_ChunkZ, a_pLuaChunk);
}
bool cPlugin_Squirrel::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnPreCrafting")) return false;
return m_Plugin->GetFunction("OnPreCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
bool cPlugin_Squirrel::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnCraftingNoRecipe")) return false;
return m_Plugin->GetFunction("OnCraftingNoRecipe").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
bool cPlugin_Squirrel::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnPostCrafting")) return false;
return m_Plugin->GetFunction("OnPostCrafting").Evaluate<bool>((cPlayer *) a_Player, (cCraftingGrid *) a_Grid, a_Recipe);
}
bool cPlugin_Squirrel::OnBlockToPickup(
BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups
)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnBlockToPickup")) return false;
return m_Plugin->GetFunction("OnBlockToPickup").Evaluate<bool>(a_BlockType, a_BlockMeta, (cPlayer *) a_Player, a_EquippedItem, a_Pickups);
}
bool cPlugin_Squirrel::OnWeatherChanged(cWorld * a_World)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnWeatherChanged")) return false;
return m_Plugin->GetFunction("OnWeatherChanged").Evaluate<bool>(a_World);
}
bool cPlugin_Squirrel::OnUpdatingSign(
cWorld * a_World,
int a_BlockX, int a_BlockY, int a_BlockZ,
AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4,
cPlayer * a_Player
)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnUpdatingSign")) return false;
return m_Plugin->GetFunction("OnUpdatingSign")
.Evaluate<bool>(
a_World,
a_BlockX,
a_BlockY,
a_BlockZ,
a_Line1,
a_Line2,
a_Line3,
a_Line4,
a_Player
);
}
bool cPlugin_Squirrel::OnUpdatedSign(
cWorld * a_World,
int a_BlockX, int a_BlockY, int a_BlockZ,
const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4,
cPlayer * a_Player
)
{
cCSLock Lock(m_CriticalSection);
if(!m_Plugin->HasFunction("OnUpdatedSign")) return false;
return m_Plugin->GetFunction("OnUpdatedSign")
.Evaluate<bool>(
a_World,
a_BlockX,
a_BlockY,
a_BlockZ,
a_Line1,
a_Line2,
a_Line3,
a_Line4,
a_Player
);
}
#endif // USE_SQUIRREL

View File

@@ -1,69 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include "Plugin.h"
#include <sqrat.h>
#include "squirrelbindings/SquirrelObject.h"
class cPlugin_Squirrel :
public cPlugin
{
public:
cPlugin_Squirrel(const char* a_PluginName);
~cPlugin_Squirrel();
void OnDisable();
bool Initialize();
void Tick(float a_Dt);
virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) override;
virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override;
virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cChunkDesc * a_pLuaChunk ) override;
virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup) override;
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
virtual bool OnPlayerJoin (cPlayer* a_Player ) override;
virtual void OnPlayerMove (cPlayer* a_Player ) override;
virtual void OnPlayerSpawn (cPlayer* a_Player ) override;
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player) override;
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override;
virtual bool OnWeatherChanged (cWorld * a_World) override;
protected:
const char * m_PluginName;
cCriticalSection m_CriticalSection;
SquirrelObject *m_Plugin;
};
#endif // USE_SQUIRREL

View File

@@ -17,11 +17,6 @@
#include "Protocol/ProtocolRecognizer.h" // for protocol version constants
#include "CommandOutput.h"
#ifdef USE_SQUIRREL
#include "squirrelbindings/SquirrelFunctions.h"
#include "squirrelbindings/SquirrelBindings.h"
#endif
#include "../iniFile/iniFile.h"
#include <iostream>
@@ -195,9 +190,6 @@ void cRoot::Start(void)
m_Authenticator.Stop();
#ifdef USE_SQUIRREL
CloseSquirrelVM();
#endif
LOG("Freeing MonsterConfig...");
delete m_MonsterConfig; m_MonsterConfig = 0;
LOG("Stopping WebAdmin...");

View File

@@ -1,118 +0,0 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
#ifdef USE_SQUIRREL
#include "SquirrelCommandBinder.h"
#include "Player.h"
#include "Plugin.h"
#include "Plugin_Squirrel.h"
#include "squirrelbindings/SquirrelArray.h"
cSquirrelCommandBinder::cSquirrelCommandBinder()
{
}
cSquirrelCommandBinder::~cSquirrelCommandBinder()
{
}
void cSquirrelCommandBinder::ClearBindings()
{
m_BoundCommands.clear();
}
void cSquirrelCommandBinder::RemoveBindingsForPlugin( cPlugin* a_Plugin )
{
for( CommandMap::iterator itr = m_BoundCommands.begin(); itr != m_BoundCommands.end(); )
{
if( itr->second.Plugin == a_Plugin )
{
LOGINFO("Unbinding %s ", itr->first.c_str( ) );
CommandMap::iterator eraseme = itr;
++itr;
m_BoundCommands.erase( eraseme );
continue;
}
++itr;
}
}
bool cSquirrelCommandBinder::BindCommand( const std::string & a_Command, const std::string & a_Permission, cPlugin* a_Plugin, Sqrat::Function a_Callback )
{
if( !a_Plugin->CanBindCommands() )
{
LOGERROR("ERROR: Trying to bind command \"%s\" to a plugin that is not initialized.", a_Command.c_str() );
return false;
}
if( m_BoundCommands.find( a_Command ) != m_BoundCommands.end() )
{
LOGERROR("ERROR: Trying to bind command \"%s\" that has already been bound.", a_Command.c_str() );
return false;
}
LOGINFO("Binding %s (%s)", a_Command.c_str(), a_Permission.c_str() );
BoundFunction Callback;
Callback.Callback = a_Callback;
Callback.Plugin = a_Plugin;
Callback.Permission = a_Permission;
m_BoundCommands[ a_Command ] = Callback;
return true;
}
bool cSquirrelCommandBinder::HandleCommand( const std::string & a_Command, cPlayer* a_Player )
{
AStringVector Split = StringSplit(a_Command, " ");
if (Split.size() == 0)
{
return false;
}
CommandMap::iterator FoundCommand = m_BoundCommands.find( Split[0] );
if( FoundCommand != m_BoundCommands.end() )
{
const BoundFunction & func = FoundCommand->second;
if( func.Permission.size() > 0 )
{
if( !a_Player->HasPermission( func.Permission.c_str() ) )
{
return false;
}
}
// Push the split
SquirrelStringArray SplitData;
std::vector<std::string>::const_iterator iter = Split.begin();
while(iter != Split.end()) {
SplitData.Add(*iter);
++iter;
}
// Push player
Sqrat::Function callback = func.Callback;
return callback.Evaluate<bool>(&SplitData, a_Player);
}
return false;
}
#endif // USE_SQUIRREL

View File

@@ -1,51 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include <sqrat.h>
class cPlugin;
class cPlayer;
class cSquirrelCommandBinder
{
public:
cSquirrelCommandBinder();
~cSquirrelCommandBinder();
bool HandleCommand( const std::string & a_Command, cPlayer* a_Player );
bool BindCommand( const std::string & a_Command, const std::string & a_Permission, cPlugin* a_Plugin, Sqrat::Function a_Callback);
void ClearBindings();
void RemoveBindingsForPlugin( cPlugin* a_Plugin );
private:
struct BoundFunction
{
Sqrat::Function Callback;
cPlugin *Plugin;
std::string Permission;
};
typedef std::map< std::string, BoundFunction > CommandMap;
CommandMap m_BoundCommands;
};
#endif // USE_SQUIRREL

View File

@@ -6,10 +6,6 @@
#include <exception> //std::exception
#include <csignal> //std::signal
#include <stdlib.h> //exit()
#ifdef USE_SQUIRREL
#include "squirrelbindings/SquirrelFunctions.h"
#include "squirrelbindings/SquirrelBindings.h"
#endif
#ifdef _MSC_VER
#include <dbghelp.h>

View File

@@ -1,56 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
template <typename T>
class SquirrelArray
{
public:
SquirrelArray()
{
}
unsigned int Size()
{
return m_Values.size();
}
T Get(unsigned int a_Index)
{
if(m_Values.size() < a_Index)
{
return T();
}
return m_Values.at(a_Index);
}
void Add(T a_Value)
{
m_Values.push_back(a_Value);
}
protected:
std::vector<T> m_Values;
};
class SquirrelStringArray : public SquirrelArray<std::string> { };
#endif // USE_SQUIRREL

View File

@@ -1,66 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include "SquirrelBindings.h"
#include "../Plugin_Squirrel.h"
#include "../PluginManager.h"
#include "../Root.h"
#include "../SquirrelCommandBinder.h"
// The baseclass for squirrel plugins
class cSquirrelBaseClass
{
public:
cSquirrelBaseClass()
: m_Instance(0)
{
}
void setInstance(cPlugin_Squirrel *a_Instance)
{
m_Instance = a_Instance;
}
void AddHook(short a_Hook)
{
if(m_Instance)
cRoot::Get()->GetPluginManager()->AddHook(m_Instance, (cPluginManager::PluginHook) a_Hook);
}
void AddCommand( std::string a_Command, std::string a_Description, std::string a_Permission )
{
if(m_Instance) m_Instance->AddCommand(a_Command, a_Description, a_Permission);
}
bool BindCommand( const std::string a_Command, const std::string a_Permission, Sqrat::Function a_Callback)
{
if(!m_Instance) return false;
return cRoot::Get()->GetPluginManager()->GetSquirrelCommandBinder()->BindCommand(a_Command, a_Permission, m_Instance, a_Callback);
}
protected:
cPlugin_Squirrel *m_Instance;
};
#endif // USE_SQUIRREL

View File

@@ -1,195 +0,0 @@
#include "Globals.h"
#ifdef USE_SQUIRREL
#include "SquirrelBindings.h"
#include "SquirrelFunctions.h"
#include "SquirrelBaseClass.h"
#include "SquirrelArray.h"
#include "../Player.h"
using namespace Sqrat;
void BindSquirrel(HSQUIRRELVM vm)
{
RootTable()
.Bind("Plugin", Class<cSquirrelBaseClass>()
.Func("AddHook", &cSquirrelBaseClass::AddHook)
.Func("AddCommand", &cSquirrelBaseClass::AddCommand)
.Func("BindCommand", &cSquirrelBaseClass::BindCommand)
);
RootTable().Bind("Vector3f", Class<Vector3f, NoConstructor>()
.Func("Set", &Vector3f::Set)
.Func("Normalize", &Vector3f::Normalize)
.Func("Length", &Vector3f::Length)
.Func("SqrLength", &Vector3f::SqrLength)
.Var("x", &Vector3f::x)
.Var("y", &Vector3f::y)
.Var("z", &Vector3f::z)
);
RootTable().Bind("Vector3d", Class<Vector3d, NoConstructor>()
.Func("Set", &Vector3d::Set)
.Func("Normalize", &Vector3d::Normalize)
.Func("Length", &Vector3d::Length)
.Func("SqrLength", &Vector3d::SqrLength)
.Var("x", &Vector3d::x)
.Var("y", &Vector3d::y)
.Var("z", &Vector3d::z)
);
RootTable().Bind("cEntity", Class<cEntity, NoConstructor>()
.Func("GetEntityType", &cEntity::GetEntityType)
.Func("IsA", &cEntity::IsA)
.Func("GetWorld", &cEntity::GetWorld)
.Func("GetPosition", &cEntity::GetPosition)
.Func("GetPosX", &cEntity::GetPosX)
.Func("GetPosY", &cEntity::GetPosY)
.Func("GetPosZ", &cEntity::GetPosZ)
.Func("GetRot", &cEntity::GetRot)
.Func("GetRotation", &cEntity::GetRotation)
.Func("GetPitch", &cEntity::GetPitch)
.Func("GetRoll", &cEntity::GetRoll)
.Func("SetRotation", &cEntity::SetRotation)
.Func("SetPitch", &cEntity::SetPitch)
.Func("SetRoll", &cEntity::SetRoll)
.Func("GetLookVector", &cEntity::GetLookVector)
.Func("GetChunkX", &cEntity::GetChunkX)
.Func("GetChunkY", &cEntity::GetChunkY)
.Func("GetChunkZ", &cEntity::GetChunkZ)
.Func("SetPosX", &cEntity::SetPosX)
.Func("SetPosY", &cEntity::SetPosY)
.Func("SetPosZ", &cEntity::SetPosZ)
.Func<void (cEntity::*) (double, double, double)>("SetPosition", &cEntity::SetPosition)
.Func("GetUniqueID", &cEntity::GetUniqueID)
.Func("IsDestroyed", &cEntity::IsDestroyed)
.Func("Destroy", &cEntity::Destroy)
);
ConstTable().Enum("MetaData", Enumeration()
.Const("Normal", cPawn::NORMAL)
.Const("Burning", cPawn::BURNING)
.Const("Crouched", cPawn::CROUCHED)
.Const("Riding", cPawn::RIDING)
.Const("Sprinting", cPawn::SPRINTING)
.Const("Eating", cPawn::EATING)
.Const("Blocking", cPawn::BLOCKING)
);
RootTable().Bind("cPawn", DerivedClass<cPawn, cEntity, NoConstructor>()
.Func("TeleportToEntity", &cPawn::TeleportToEntity)
.Func("TeleportTo", &cPawn::TeleportTo)
.Func("Heal", &cPawn::Heal)
.Func("TakeDamage", &cPawn::TakeDamage)
.Func("KilledBy", &cPawn::KilledBy)
.Func("GetHealth", &cPawn::GetHealth)
.Func("SetMetaData", &cPawn::SetMetaData)
.Func("GetMetaData", &cPawn::GetMetaData)
.Func("SetMaxHealth", &cPawn::SetMaxHealth)
.Func("GetMaxHealth", &cPawn::GetMaxHealth)
);
RootTable().Bind("cPlayer", DerivedClass<cPlayer, cPawn, NoConstructor>()
.Func("GetName", &cPlayer::GetName)
.Func("SetTouchGround", &cPlayer::SetTouchGround)
.Func("SetStance", &cPlayer::SetStance)
.Func("GetEyeHeight", &cPlayer::GetEyeHeight)
.Func("GetEyePosition", &cPlayer::GetEyePosition)
.Func("GetFlying", &cPlayer::GetFlying)
.Func("GetStance", &cPlayer::GetStance)
//TODO .Func("GetInventory", &cPlayer::GetInventory)
.Func("TeleportTo", &cPlayer::TeleportTo)
.Func("GetGameMode", &cPlayer::GetGameMode)
.Func("GetIP", &cPlayer::GetIP)
.Func("GetLastBlockActionTime", &cPlayer::GetLastBlockActionTime)
.Func("GetLastBlockActionCnt", &cPlayer::GetLastBlockActionCnt)
.Func("SetLastBlockActionCnt", &cPlayer::SetLastBlockActionCnt)
.Func("SetLastBlockActionTime", &cPlayer::SetLastBlockActionTime)
.Func("SetGameMode", &cPlayer::SetGameMode)
.Func("LoginSetGameMode", &cPlayer::LoginSetGameMode)
.Func("SetIP", &cPlayer::SetIP)
.Func("MoveTo", &cPlayer::MoveTo)
.Func("GetClientHandle", &cPlayer::GetClientHandle)
.Func("SendMessage", &cPlayer::SendMessage)
.Func("AddToGroup", &cPlayer::AddToGroup)
.Func("CanUseCommand", &cPlayer::CanUseCommand)
.Func("HasPermission", &cPlayer::HasPermission)
.Func("IsInGroup", &cPlayer::IsInGroup)
.Func("GetColor", &cPlayer::GetColor)
.Func("TossItem", &cPlayer::TossItem)
.Func("Heal", &cPlayer::Heal)
.Func("Feed", &cPlayer::Feed)
.Func("TakeDamage", &cPlayer::TakeDamage)
.Func("KilledBy", &cPlayer::KilledBy)
.Func("Respawn", &cPlayer::Respawn)
.Func("SetVisible", &cPlayer::SetVisible)
.Func("IsVisible", &cPlayer::IsVisible)
.Func("MoveToWorld", &cPlayer::MoveToWorld)
.Func("GetLoadedWorldName", &cPlayer::GetLoadedWorldName)
.Func("UseEquippedItem", &cPlayer::UseEquippedItem)
);
RootTable().Bind("StringArray", Class<SquirrelStringArray>()
.Func("Get", &SquirrelStringArray::Get)
.Func("Add", &SquirrelStringArray::Add)
.Func("Size", &SquirrelStringArray::Size)
);
RootTable().Func("print", &sqPrint);
ConstTable().Enum("Hook", Enumeration()
.Const("Tick", cPluginManager::HOOK_TICK)
.Const("Chat", cPluginManager::HOOK_CHAT)
.Const("CollectPickup", cPluginManager::HOOK_COLLECT_PICKUP)
.Const("BlockDig", cPluginManager::HOOK_BLOCK_DIG)
.Const("BlockPlace", cPluginManager::HOOK_BLOCK_PLACE)
.Const("Disconnect", cPluginManager::HOOK_DISCONNECT)
.Const("Handshake", cPluginManager::HOOK_HANDSHAKE)
.Const("Login", cPluginManager::HOOK_LOGIN)
.Const("PlayerSpawn", cPluginManager::HOOK_PLAYER_SPAWN)
.Const("PlayerJoin", cPluginManager::HOOK_PLAYER_JOIN)
.Const("PlayerMove", cPluginManager::HOOK_PLAYER_MOVE)
.Const("TakeDamage", cPluginManager::HOOK_TAKE_DAMAGE)
.Const("Killed", cPluginManager::HOOK_KILLED)
.Const("ChunkGenerated", cPluginManager::HOOK_CHUNK_GENERATED)
.Const("ChunkGenerating", cPluginManager::HOOK_CHUNK_GENERATING)
.Const("BlockToDrops", cPluginManager::HOOK_BLOCK_TO_DROPS)
.Const("PreCrafting", cPluginManager::HOOK_PRE_CRAFTING)
.Const("CraftingNoRecipe", cPluginManager::HOOK_CRAFTING_NO_RECIPE)
.Const("PostCrafting", cPluginManager::HOOK_POST_CRAFTING)
.Const("BlockToPickup", cPluginManager::HOOK_BLOCK_TO_PICKUP)
.Const("WeatherChanged", cPluginManager::HOOK_WEATHER_CHANGED)
.Const("UpdatingSign", cPluginManager::HOOK_UPDATING_SIGN)
.Const("UpdatedSign", cPluginManager::HOOK_UPDATED_SIGN));
}
#endif // USE_SQUIRREL

View File

@@ -1,32 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include <squirrel.h>
#include <sqrat.h>
void BindSquirrel(HSQUIRRELVM vm);
#endif // USE_SQUIRREL

View File

@@ -1,94 +0,0 @@
#include "Globals.h"
#ifdef USE_SQUIRREL
#include "SquirrelFunctions.h"
#include "SquirrelBindings.h"
static HSQUIRRELVM squirrelvm = NULL;
SQInteger runtimeErrorHandler(HSQUIRRELVM a_VM)
{
const SQChar *sErr = 0;
if(sq_gettop(a_VM) >= 1)
{
if(SQ_SUCCEEDED(sq_getstring(a_VM, 2, &sErr)))
{
LOGERROR("Squirrel Error: %s", sErr);
}
else
{
LOGERROR("Squirrel Error: Unknown Error");
}
}
return 0;
}
void compilerErrorHandler(HSQUIRRELVM v,
const SQChar* a_Desc,
const SQChar* a_Source,
SQInteger a_Line,
SQInteger a_Column)
{
LOGERROR("Squirrel Error: %s (%d:%d) %s", a_Source, a_Line, a_Column, a_Desc);
}
HSQUIRRELVM OpenSquirrelVM()
{
if(!squirrelvm)
{
squirrelvm = sq_open(1024);
Sqrat::DefaultVM::Set(squirrelvm);
sq_newclosure(squirrelvm, runtimeErrorHandler, 0);
sq_seterrorhandler(squirrelvm);
sq_setcompilererrorhandler(squirrelvm, compilerErrorHandler);
BindSquirrel(squirrelvm);
}
return squirrelvm;
}
void CloseSquirrelVM()
{
if(squirrelvm)
{
sq_close(squirrelvm);
squirrelvm = NULL;
}
}
void sqPrint(SQChar * text)
{
LOGINFO("%s", text);
}
#endif // USE_SQUIRREL

View File

@@ -1,28 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include <sqrat.h>
HSQUIRRELVM OpenSquirrelVM();
void CloseSquirrelVM();
void sqPrint(SQChar * text);
#endif // USE_SQUIRREL

View File

@@ -1,55 +0,0 @@
#pragma once
#ifdef USE_SQUIRREL
#include <sqrat.h>
class SquirrelObject
{
public:
SquirrelObject(Sqrat::Object a_Obj)
{
m_SquirrelObject = a_Obj;
}
Sqrat::Function GetFunction(const char *a_MethodName)
{
if(m_SquirrelObject.IsNull())
return Sqrat::Function();
Sqrat::Function method(m_SquirrelObject, a_MethodName);
return method;
}
bool HasFunction(const char *a_MethodName)
{
return !this->GetFunction(a_MethodName).IsNull();
}
protected:
Sqrat::Object m_SquirrelObject;
};
#endif // USE_SQUIRREL

View File

@@ -1,41 +0,0 @@
Squirrel 3.0 stable
--------------------------------------------------------
What is in this distribution?
squirrel
static library implementing the compiler and interpreter of the language
sqstdlib
the standard utility libraries
sq
stand alone interpreter
doc
The manual
etc
a minimalistic embedding sample
samples
samples programs
HOW TO COMPILE
---------------------------------------------------------
GCC USERS
.........................................................
There is a very simple makefile that compiles all libraries and exes
from the root of the project run 'make'
for 32 bits systems
$ make
for 64 bits systems
$ make sq64
VISUAL C++ USERS
.........................................................
Open squirrel.dsw from the root project directory and build(dho!)

View File

@@ -1,21 +0,0 @@
Copyright (c) 2003-2011 Alberto Demichelis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------
END OF COPYRIGHT

View File

@@ -1,422 +0,0 @@
***version 3.0.1 stable***
-added # as alternative symbol for "line comment"(mostly useful for shell scripts)
-added sq_throwobject() to throw an arbitrary object from the C API
-added alignement flag for userdata types, SQ_ALIGNMENT (thx Shigemasa)
-added rawset() and rawget() to class and instance default delegate
-changed bytecode format now ensures matching integer size and float size
-now inherited classes also inherit userdatasize
-added SQUIRREL_VERSION_NUMBER in squirrel.h and _versionnumber_ global symbol
-fixed sq_getmemberhandle
-fixed sq_getrefcount
-refactored some sqstdio code
-refactored some clone code
-refactored some stuff in the string lib
-added -s and -fno-exceptions in GCC makefile(better performance when using GCC)
***2011-03-13 ***
***version 3.0 stable***
-added sq_getcallee()
-sq_getfreevariable() also works for native closures
-minior optimizations
-removed several warning when compiling with GCC 4.x
-fixed some errors in the documentation
-fixed bug when using SQUSEDOUBLE and 32bits intengers
-fixed bug when invoking generators with closure.call() (thx huntercool)
***2010-12-19 ***
***version 3.0 release candidate 1(RC 1)***
-improved metamethods error handling
-added parameter 'isstatic' to _newmember metamethod(thx G.Meyer)
-added sq_getrefcount() to return number of refences from C++(thx G.Meyer)
***2010-11-07 ***
***version 3.0 beta 3***
-license changed to "MIT license"
-added sq_resurrectunreachable() and resurrectunreachable()
-added callee() built in function, returns the current running closure
-added thread.getstackinfos()
-added sq_objtouserpointer()
-added sq_newtableex()
-various refactoring and optimizations
-fixed several 64bits issues regarding integer to string conversions
-fixed some bugs when SQUSEDOUBLE is used in 32bits systems
***2010-08-18 ***
***version 3.0 beta 2.1***
-fixed bug in class constructor
-fixed bug in compound arith
***2010-08-12 ***
***version 3.0 beta 2***
-class methods can be added or replaced after the class as been instantiated
-JSON compliant table syntax, this is currently an experimental feature (thx atai)
-sq_getsize() now returns userdatasize for classes and instances
-now setroottable() and setconsttable() return the previous value of the respective table
-fixed bug in compound arith operators when used on a free variable (thx ellon)
-fixed some x64 minor bugs
-fixed minor bug in the compiler
-refactored some VM internals
-documented sq_getmemberhandle, sq_getbyhandle, sq_setbyhandle to set and get value from classes
***2009-11-15 ***
***version 3.0 beta 1***
-various refactoring and optimizations
-fixed bug in free variables (thx mokehehe)
-fixed bug in functions with default parameters (thx ara & Yexo)
-fixed bug in exception handling
-improved error propagation in _set and _get metamethods ( and 'throw null' for clean failure)
-added sq_getmemberhandle, sq_getbyhandle, sq_setbyhandle to set and get value from classes
***2009-06-30 ***
***version 3.0 alpha 2***
-added real free variables(thx Paul Ruizendaal)
-added refactored function call implementation and compiler(thx Paul Ruizendaal)
-added sq_getfunctioninfo
-added compile time flag SQUSEDOUBLE to use double precision floats
-added global slot _floatsize_ int the base lib to recognize single precision and double precision builds
-sq_wakeupvm can now resume the vm with an exception
-added sqstd_format
-now blobs can be cloned
-generators can now be instantiated by calling sq_call() or closure.call()
-fixed debughook bug
-fixed cooroutine error propagation
***2008-07-23 ***
***version 3.0 alpha 1***
-first branch from 2.x source tree
-added 'base' keyword
-removed 'delegate' keyword
-now compiled scripts are vararg functions
-added setdelegate() and getdelegate() table builtin methods
-added <=> 3 ways compare operator
-added lambda expression @(a,b) a + b
-added local function statement
-added array built-in map(),reduce(),apply(),filter() and find()
-generators hold only a weak reference of the enviroment object
-removed 'vargv' and 'vargc' keywords
-now var args are passed as an array called vargv(as a paramter)
-removed 'parent' keyword
-added class getbase() built in method
-instanceof doesn't throw an exception if the left expression is not a class
-lexical scoping for free variables(free variables are no longer in the second parameter list)
-sq_setprintfunc accept error func
-sq_geterrorfunc()
-added sq_arrayremove() and sq_arrayinsert()
-error() built in function(works like print but prints using the errorfunc)
-added native debug hook
***2008-02-17 ***
***version 2.2 stable***
-added _newslot metamethod in classes
-added enums added constants
-added sq_pushconsttable, sq_setconsttable
-added default param
-added octal literals(thx Dinosaur)
-fixed debug hook, 'calls' and 'returns' are properly notified in the same number.
-fixed a coroutine bug
***2007-07-29 ***
***version 2.1.2 stable***
-new behaviour for generators iteration using foreach
now when a generator is iterated by foreach the value returned by a 'return val' statement
will terminate the iteration but will not be returned as foreach iteration
-added sq_setclassudsize()
-added sq_clear()
-added table.clear(), array.clear()
-fixed sq_cmp() (thx jyuill)
-fixed minor bugs
***2006-08-21 ***
***version 2.1.1 stable***
-vm refactoring
-optimized internal function memory layout
-new global symbol _version_ (is the version string)
-code size optimization for float literals(on 32bits float builts)
-now the raw ref API(sq_addref etc...) is fully reentrant.
-fixed a bug in sq_getdelegate() now pushes null if the object doesn't have a delegate(thx MatzeB)
-improved C reference performances in NO_GARBAGE_COLLECTOR builds
-sq_getlocal() now enumerates also outer values.
-fixed regexp library for GCC users.
***2006-03-19 ***
***version 2.1 stable***
-added static class fields, new keyword static
-added 64bits architecture support
-added global slot _intsize_ int the base lib to recognize 32bits and 64bits builds
-added functions with fixed environment, closure.bindenv() built-in function
-all types except userdata and null implement the tostring() method
-string concatenation now invokes metamethod _tostring
-new metamethods for class objects _newmember and _inherited
-sq_call() sq_resume() sq_wakeupvm() have a new signature
-new C referencing implementation(scales more with the amount of references)
-refactored hash table
-new api functions sq_newslot(),sq_tobool(),sq_getbase(), sq_instanceof(), sq_bindenv()
-the api func sq_createslot was deprecated but still supported in form of C macro on top of sq_newslot
-sq_setreleasehook() now also works for classes
-stream.readstr() and stream.writestr() have been deprecated(this affects file and blob)
-fixed squirrel.h undeclared api calls
-fixed few minor bugs
-SQChar is now defined as wchar_t
-removed warning when building with -Wall -pedantic for GCC users
-added new std io function writeclosuretofile()
-added new std string functions strip(),rstrip(),lstrip() and split()
-regular expressions operators (+,*) now have more POSIX greedyness behaviour
-class constructors are now invoked as normal functions
***2005-10-02 ***
***version 2.0.5 stable***
-fixed some 64bits incompatibilities (thx sarge)
-fixed minor bug in the stdlib format() function (thx Rick)
-fixed a bug in dofile() that was preventing to compile empty files
-added new API sq_poptop() & sq_getfreevariable()
-some performance improvements
***2005-08-14 ***
***version 2.0.4 stable***
-weak references and related API calls
-added sq_objtobool()
-class instances memory policies improved(1 mem allocation for the whole instance)
-typetags are now declared as SQUserPointer instead of unsigned int
-first pass for 64bits compatibility
-fixed minor bug in the stdio stream
-fixed a bug in format()
-fixed bug in string.tointeger() and string.tofloat()
***2005-06-24 ***
***version 2.0.3 stable***
-dofile() and loadfile() in the iolib now can decode ASCII, UTF8 files UCS2 big-endian and little-endian
-sq_setparamscheck() : now typemesk can check for null
-added string escape sequence \xhhhh
-fixed some C++ standard incompatibilities
***2005-05-15 ***
***version 2.0.2 stable***
-performances improvements (expecially for GCC users)
-removed all dependencies from C++ exception handling
-various bugfixes
***2005-04-12 ***
***version 2.0.1 stable***
-various bugfixes
-sq_setparamscheck() now allows spaces in the typemask
***2005-04-03 ***
***version 2.0 stable***
-added API sq_gettypetag()
-added built-in function to the bool type(tointeger, tostring etc...)
***2005-02-27 ***
***version 2.0 release candidate 1(RC 1)***
-added API sq_reseterror()
-modified sq_release()
-now class instances can be cloned
-various bufixes
***2005-01-26 ***
***version 2.0 beta 1***
-added bool type
-class properties can be redefined in a derived class
-added ops *= /= and %=
-new syntax for class attributes declaration </ and /> instead of ( and )
-increased the max number of literals per function from 65535 to 16777215
-now free variables have proper lexical scoping
-added API sq_createinstance(), sq_pushbool(), sq_getbool()
-added built-in function type()
-added built-in function obj.rawin(key) in table,class and instance
-sq_rawget() and sq_rawset() now work also on classes and instances
-the VM no longer uses C++ exception handling (more suitable for embedded devices)
-various bufixes
***2004-12-21 ***
***version 2.0 alpha 2***
-globals scoping changed, now if :: is omitted the VM automatically falls back on the root table
-various bufixes
-added class level attributes
***2004-12-12 ***
***version 2.0 alpha 1***
-codebase branch from version 1.x
-added classes
-added functions with variable number of parameters(vargc & vargv and the ...)
-0 and 0.0 are now considered 'false' by all conditional statements(if,while,for,?,do-while)
-added new api functions sq_newclass() sq_setinstanceup() sq_getinstanceup() sq_getattributes() sq_setattributes()
-modified api sq_settypetag()
***2004-11-01 ***
***version 1.0 stable***
-fixed some minor bug
-improved operator 'delete' performances
-added scientific notation for float numbers( eg. 2.e16 or 2.e-2)
***2004-08-30 ***
***version 1.0 release candidate 2(RC 2)***
-fixed bug in the vm(thx Pierre Renaux)
-fixed bug in the optimizer(thx Pierre Renaux)
-fixed some bug in the documentation(thx JD)
-added new api functions for raw object handling
-removed nested multiline comments
-reduced memory footprint in C references
***2004-08-23 ***
***version 1.0 release candidate 1(RC 1)***
-fixed division by zero
-the 'in' operator and obj.rawget() do not query the default delegate anymore
-added function sq_getprintfunc()
-added new standard library 'auxlib'(implements default error handlers)
***2004-07-12 ***
***version 1.0 beta 4***
-fixed a bug in the integer.tochar() built-in method
-fixed unary minus operator
-fixed bug in dofile()
-fixed inconsistency between != and == operators(on float/integer comparison)
-added javascript style unsigned right shift operator '>>>'
-added array(size) constructor built-in function
-array.resize(size,[fill]) built-in function accepts an optional 'fill' value
-improved debug API, added sq_getclosureinfo() and sq_setnativeclosurename()
***2004-05-23 ***
***version 1.0 beta 3***
-minor vm bug fixes
-string allocation is now faster
-tables and array memory usage is now less conservative(they shrink)
-added regular expression routines in the standard library
-The 'c' expression now accepts only 1 character(thx irbrian)
-multiline strings <[ ]> have been substituted with C# style verbatim strings (eg. @"string")
-added new keyword 'parent' for accessing the delegate of tables and unserdata
-The metamethod '_clone' has been renamed '_cloned'
-the _delslot metamethod's behaviour and prototype have been changed
-new default function in the integer and float object 'tochar()'
-the built-in function chcode2string has been removed
-the default method [table].getdelegate() has been removed
-new api sq_rawdeleteslot()
-new table built-in method rawdelete(key)
-the dynamic mudule loading has been removed from the standard distribution
-some optimizations in the VM
***2004-04-21 ***
***version 1.0 beta 2***
-minor compiler/parser bug fixes
-sq_newclosure has a different prototype, the "paramscheck" of paramter has been moved to the new function sq_setparamscheck()
-sq_setparamscheck allows to add automatic parameters type checking in native closures
-sq_compile() lost the lineinfo parameter
-new api sq_enabledebuginfo() globally sets compiler's debug info generation
-added consistency check on bytecode serialization
-fixed += operator, now works on strings like +
-added global slot in the base lib _charsize_ to recognize unicode builds from ascii builds runtime
-added registry table
-new api call sq_pushregistrytable()
-added type tag to the userdata type sq_settypetag()
-sq_getuserdata now queries the userdata typetag
-the built in function collect_garbage() as been renamed collectgarbage() for consistency reasons
-new standard libraries(sqlibs are now obsolete)
***2004-02-20 ***
***version 1.0 beta 1***
-fixed a bug in the compiler (thanks Martin Kofler)
-fixed bug in the switch case statement
-fixed the _unm metamethod
-fixed minor bugs in the API
-fixed automatic stack resizing
-first beta version
first pass code clean up in the VM and base lib
first pass code coverege test has been done on VM and built-in lib
-new VM creation API sq_open() sq_close() (sq_newvm and sq_releasevm are now obsolete)
-new api allows to specifiy a "print" function to output text(sq_printfunc)
-added some small optimizations
-new cooperative multi-threading capabilities in the base library(coroutines), VMs are now a built in type("thread")
-new built in functions have been added for manipulating the new "thread" type
-friend virtual machines share the same root table, error handler and debug hook by default
-new compile time options
***2004-01-19 ***
***version 0.9 alpha***
-fixed a garbage collection bug
-fixed some API bugs(thanks to Joshua Jensen)
-fixed tail calls (in the version 0.8 the tail call optimization was erroneously disabled)
-new function parameters semantic, now passing a wrong number of parameters generates an exception
-native closures have now a built in parameter number checking
-sq_rawget and sq_rawset now work also on arrays
-sq_getsize now woks also on userdata
-the userdata release hook prototype is changed(now passes the size of the userdata)
-the lexer reader function now returns an integer instead of a char that allows better error checking on the input(thx Joshua Jensen)
-faster compiler
-try/catch blocks do not cause any runtime memory allocation anymore
***2003-12-06 ***
***version 0.8 alpha***
-fixed a bug that was preventing to have callable userdata throught the metamethod _call
-fixed a garbage collection bug
-fixed == operator now can compare correctly different types
-new built in method getstackinfos(level)
-improved line informations precision for the debug hook
-new api call sq_compilebuffer()
-new built-in api function compilestring()
-new syntactic sugar for function declarations inside tables
-the debug API has been finalized
***2003-11-17 ***
***version 0.7 alpha***
-fixed critical bug SQInteger the tail call system
-fixed bug in the continue statement code generation
-fixed func call param issue(thanks to Rewoonenco Andrew)
-added _delslot metamethod(thanks to Rewoonenco Andrew)
-new multiline string expression ( delimited by <[ and ]> )
-normal strings ("") do not allow embedded new line anymore
-reduced vm memory footprint(C refs are shared between friend VMs)
-new api method sq_deleteslot()
-new debug hook event 'r' is triggered when a function returns
***2003-11-04 ***
***version 0.6 alpha***
-fixed switch statement(was executing the default case after a break)
-sq_call() doesn't pop the closure (just the params)
-the vm execution can be suspended from the C API anytime (micro-threads)
-new api calls sq_suspendvm() sq_wakeupvm() sq_getvmstate() and sq_reservestack()
***2003-10-13 ***
***version 0.5 alpha***
-fixed some minor bug
-tested with non ASCII identifiers in unicode mode(I've tried chinese chars)
-added built-in function string.find()
-the built-in function array.sort() optionally accepts a cmp(a,b) function
-the debug hook function now has a new prototype debug_hook(event_type,sourcefile,line,functionname)
-fixed some debug info imprecision
***2003-10-01 ***
***version 0.4 alpha***
-faster VM
-sq_call will pop arguments and closure also in case of failure
-fixed a bug in sq_remove
-now the VM detects delegation cycles(and throws an exception)
-new operators ++ and --
-new operator ',' comma operator
-fixed some expression precedence issue
-fixed bug in sq_arraypop
***2003-09-15 ***
***version 0.3 alpha***
-fixed a bug in array::insert()
-optional Unicode core(define SQUNICODE or _UNICODE on Win32)
-sq_compiler uses a new reader function SQLEXREADFUNC
-the debug hook passes 'l' instead of 'line' for line callbacks
and 'c' instead of 'call' for call callbacks
-new array.extend() bulit-in function
-new API sq_clone()
***2003-09-10 ***
***version 0.2 pre-alpha***
-new completely reentrant VM (sq_open and sq_close are now obsolete)
-sq_newvm() has a new prototype
-allocators are now global and linked in the VM
-_newslot meta method added
-rawset creates a slot if doesn't exists
-the compiler error callback pass the vm handle(thanks Pierre Renaux)
-sq_setforeignptr() sq_getforeingptr() are now public
-sq_resume() now is possible to resume generators from C
-sq_getlasterror() retrieve the last thrown error
-improved docs
***2003-09-06 ***
***version 0.1 pre-alpha***
first release

View File

@@ -1,18 +0,0 @@
SQUIRREL=.
MAKE=make
sq32:
cd squirrel; $(MAKE)
cd sqstdlib; $(MAKE)
cd sq; $(MAKE)
sqprof:
cd squirrel; $(MAKE) sqprof
cd sqstdlib; $(MAKE) sqprof
cd sq; $(MAKE) sqprof
sq64:
cd squirrel; $(MAKE) sq64
cd sqstdlib; $(MAKE) sq64
cd sq; $(MAKE) sq64

View File

@@ -1,23 +0,0 @@
The programming language SQUIRREL 3.0 stable
--------------------------------------------------
The project has been compiled and run on Windows(x86 and x64) and
Linux(x86 and x64) and Solaris(x86 and x64).
Has been tested with the following compilers:
MS Visual C++ 6.0,7.0,7.1,8.0,9.0,10.0 (32 and 64bits)
MinGW gcc 3.2 (mingw special 20020817-1)
Cygnus gcc 3.2
Linux gcc 3.2.3
Linux gcc 4.0.0 (x86 & 64bits)
Solaris gcc 4.0.0 (x86 & 64bits)
Feedback and suggestions are appreciated
project page - http://www.squirrel-lang.org
community forums - http://forum.squirrel-lang.org
wiki - http://wiki.squirrel-lang.org
author - alberto@demichelis.net
END OF README

View File

@@ -1,16 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_AUXLIB_H_
#define _SQSTD_AUXLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API void sqstd_seterrorhandlers(HSQUIRRELVM v);
SQUIRREL_API void sqstd_printcallstack(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* _SQSTD_AUXLIB_H_ */

View File

@@ -1,20 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTDBLOB_H_
#define _SQSTDBLOB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQUserPointer sqstd_createblob(HSQUIRRELVM v, SQInteger size);
SQUIRREL_API SQRESULT sqstd_getblob(HSQUIRRELVM v,SQInteger idx,SQUserPointer *ptr);
SQUIRREL_API SQInteger sqstd_getblobsize(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sqstd_register_bloblib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTDBLOB_H_*/

View File

@@ -1,53 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTDIO_H_
#define _SQSTDIO_H_
#ifdef __cplusplus
#define SQSTD_STREAM_TYPE_TAG 0x80000000
struct SQStream {
virtual SQInteger Read(void *buffer, SQInteger size) = 0;
virtual SQInteger Write(void *buffer, SQInteger size) = 0;
virtual SQInteger Flush() = 0;
virtual SQInteger Tell() = 0;
virtual SQInteger Len() = 0;
virtual SQInteger Seek(SQInteger offset, SQInteger origin) = 0;
virtual bool IsValid() = 0;
virtual bool EOS() = 0;
};
extern "C" {
#endif
#define SQ_SEEK_CUR 0
#define SQ_SEEK_END 1
#define SQ_SEEK_SET 2
typedef void* SQFILE;
SQUIRREL_API SQFILE sqstd_fopen(const SQChar *,const SQChar *);
SQUIRREL_API SQInteger sqstd_fread(SQUserPointer, SQInteger, SQInteger, SQFILE);
SQUIRREL_API SQInteger sqstd_fwrite(const SQUserPointer, SQInteger, SQInteger, SQFILE);
SQUIRREL_API SQInteger sqstd_fseek(SQFILE , SQInteger , SQInteger);
SQUIRREL_API SQInteger sqstd_ftell(SQFILE);
SQUIRREL_API SQInteger sqstd_fflush(SQFILE);
SQUIRREL_API SQInteger sqstd_fclose(SQFILE);
SQUIRREL_API SQInteger sqstd_feof(SQFILE);
SQUIRREL_API SQRESULT sqstd_createfile(HSQUIRRELVM v, SQFILE file,SQBool own);
SQUIRREL_API SQRESULT sqstd_getfile(HSQUIRRELVM v, SQInteger idx, SQFILE *file);
//compiler helpers
SQUIRREL_API SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror);
SQUIRREL_API SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror);
SQUIRREL_API SQRESULT sqstd_writeclosuretofile(HSQUIRRELVM v,const SQChar *filename);
SQUIRREL_API SQRESULT sqstd_register_iolib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTDIO_H_*/

View File

@@ -1,15 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_MATH_H_
#define _SQSTD_MATH_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQRESULT sqstd_register_mathlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTD_MATH_H_*/

View File

@@ -1,33 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_STRING_H_
#define _SQSTD_STRING_H_
#ifdef __cplusplus
extern "C" {
#endif
typedef unsigned int SQRexBool;
typedef struct SQRex SQRex;
typedef struct {
const SQChar *begin;
SQInteger len;
} SQRexMatch;
SQUIRREL_API SQRex *sqstd_rex_compile(const SQChar *pattern,const SQChar **error);
SQUIRREL_API void sqstd_rex_free(SQRex *exp);
SQUIRREL_API SQBool sqstd_rex_match(SQRex* exp,const SQChar* text);
SQUIRREL_API SQBool sqstd_rex_search(SQRex* exp,const SQChar* text, const SQChar** out_begin, const SQChar** out_end);
SQUIRREL_API SQBool sqstd_rex_searchrange(SQRex* exp,const SQChar* text_begin,const SQChar* text_end,const SQChar** out_begin, const SQChar** out_end);
SQUIRREL_API SQInteger sqstd_rex_getsubexpcount(SQRex* exp);
SQUIRREL_API SQBool sqstd_rex_getsubexp(SQRex* exp, SQInteger n, SQRexMatch *subexp);
SQUIRREL_API SQRESULT sqstd_format(HSQUIRRELVM v,SQInteger nformatstringidx,SQInteger *outlen,SQChar **output);
SQUIRREL_API SQRESULT sqstd_register_stringlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQSTD_STRING_H_*/

View File

@@ -1,15 +0,0 @@
/* see copyright notice in squirrel.h */
#ifndef _SQSTD_SYSTEMLIB_H_
#define _SQSTD_SYSTEMLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
SQUIRREL_API SQInteger sqstd_register_systemlib(HSQUIRRELVM v);
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /* _SQSTD_SYSTEMLIB_H_ */

View File

@@ -1,500 +0,0 @@
/*
Copyright (c) 2003-2011 Alberto Demichelis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _SQUIRREL_H_
#define _SQUIRREL_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef SQUIRREL_API
#define SQUIRREL_API extern
#endif
#if (defined(_WIN64) || defined(_LP64))
#ifndef _SQ64
#define _SQ64
#endif
#endif
#ifdef _SQ64
#ifdef _MSC_VER
typedef __int64 SQInteger;
typedef unsigned __int64 SQUnsignedInteger;
typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
#else
typedef long long SQInteger;
typedef unsigned long long SQUnsignedInteger;
typedef unsigned long long SQHash; /*should be the same size of a pointer*/
#endif
typedef int SQInt32;
typedef unsigned int SQUnsignedInteger32;
#else
typedef int SQInteger;
typedef int SQInt32; /*must be 32 bits(also on 64bits processors)*/
typedef unsigned int SQUnsignedInteger32; /*must be 32 bits(also on 64bits processors)*/
typedef unsigned int SQUnsignedInteger;
typedef unsigned int SQHash; /*should be the same size of a pointer*/
#endif
#ifdef SQUSEDOUBLE
typedef double SQFloat;
#else
typedef float SQFloat;
#endif
#if defined(SQUSEDOUBLE) && !defined(_SQ64) || !defined(SQUSEDOUBLE) && defined(_SQ64)
#ifdef _MSC_VER
typedef __int64 SQRawObjectVal; //must be 64bits
#else
typedef long long SQRawObjectVal; //must be 64bits
#endif
#define SQ_OBJECT_RAWINIT() { _unVal.raw = 0; }
#else
typedef SQUnsignedInteger SQRawObjectVal; //is 32 bits on 32 bits builds and 64 bits otherwise
#define SQ_OBJECT_RAWINIT()
#endif
#ifndef SQ_ALIGNMENT // SQ_ALIGNMENT shall be less than or equal to SQ_MALLOC alignments, and its value shall be power of 2.
#if defined(SQUSEDOUBLE) || defined(_SQ64)
#define SQ_ALIGNMENT 8
#else
#define SQ_ALIGNMENT 4
#endif
#endif
typedef void* SQUserPointer;
typedef SQUnsignedInteger SQBool;
typedef SQInteger SQRESULT;
#define SQTrue (1)
#define SQFalse (0)
struct SQVM;
struct SQTable;
struct SQArray;
struct SQString;
struct SQClosure;
struct SQGenerator;
struct SQNativeClosure;
struct SQUserData;
struct SQFunctionProto;
struct SQRefCounted;
struct SQClass;
struct SQInstance;
struct SQDelegable;
struct SQOuter;
#ifdef _UNICODE
#define SQUNICODE
#endif
#ifdef SQUNICODE
#if (defined(_MSC_VER) && _MSC_VER >= 1400) // 1400 = VS8
#if !defined(_NATIVE_WCHAR_T_DEFINED) //this is if the compiler considers wchar_t as native type
#define wchar_t unsigned short
#endif
#else
typedef unsigned short wchar_t;
#endif
typedef wchar_t SQChar;
#define _SC(a) L##a
#define scstrcmp wcscmp
#define scsprintf swprintf
#define scstrlen wcslen
#define scstrtod wcstod
#ifdef _SQ64
#define scstrtol _wcstoi64
#else
#define scstrtol wcstol
#endif
#define scatoi _wtoi
#define scstrtoul wcstoul
#define scvsprintf vswprintf
#define scstrstr wcsstr
#define scisspace iswspace
#define scisdigit iswdigit
#define scisxdigit iswxdigit
#define scisalpha iswalpha
#define sciscntrl iswcntrl
#define scisalnum iswalnum
#define scprintf wprintf
#define MAX_CHAR 0xFFFF
#else
typedef char SQChar;
#define _SC(a) a
#define scstrcmp strcmp
#define scsprintf sprintf
#define scstrlen strlen
#define scstrtod strtod
#ifdef _SQ64
#ifdef _MSC_VER
#define scstrtol _strtoi64
#else
#define scstrtol strtoll
#endif
#else
#define scstrtol strtol
#endif
#define scatoi atoi
#define scstrtoul strtoul
#define scvsprintf vsprintf
#define scstrstr strstr
#define scisspace isspace
#define scisdigit isdigit
#define scisxdigit isxdigit
#define sciscntrl iscntrl
#define scisalpha isalpha
#define scisalnum isalnum
#define scprintf printf
#define MAX_CHAR 0xFF
#endif
#ifdef _SQ64
#define _PRINT_INT_PREC _SC("ll")
#define _PRINT_INT_FMT _SC("%lld")
#else
#define _PRINT_INT_FMT _SC("%d")
#endif
#define SQUIRREL_VERSION _SC("Squirrel 3.0.1 stable")
#define SQUIRREL_COPYRIGHT _SC("Copyright (C) 2003-2011 Alberto Demichelis")
#define SQUIRREL_AUTHOR _SC("Alberto Demichelis")
#define SQUIRREL_VERSION_NUMBER 301
#define SQ_VMSTATE_IDLE 0
#define SQ_VMSTATE_RUNNING 1
#define SQ_VMSTATE_SUSPENDED 2
#define SQUIRREL_EOB 0
#define SQ_BYTECODE_STREAM_TAG 0xFAFA
#define SQOBJECT_REF_COUNTED 0x08000000
#define SQOBJECT_NUMERIC 0x04000000
#define SQOBJECT_DELEGABLE 0x02000000
#define SQOBJECT_CANBEFALSE 0x01000000
#define SQ_MATCHTYPEMASKSTRING (-99999)
#define _RT_MASK 0x00FFFFFF
#define _RAW_TYPE(type) (type&_RT_MASK)
#define _RT_NULL 0x00000001
#define _RT_INTEGER 0x00000002
#define _RT_FLOAT 0x00000004
#define _RT_BOOL 0x00000008
#define _RT_STRING 0x00000010
#define _RT_TABLE 0x00000020
#define _RT_ARRAY 0x00000040
#define _RT_USERDATA 0x00000080
#define _RT_CLOSURE 0x00000100
#define _RT_NATIVECLOSURE 0x00000200
#define _RT_GENERATOR 0x00000400
#define _RT_USERPOINTER 0x00000800
#define _RT_THREAD 0x00001000
#define _RT_FUNCPROTO 0x00002000
#define _RT_CLASS 0x00004000
#define _RT_INSTANCE 0x00008000
#define _RT_WEAKREF 0x00010000
#define _RT_OUTER 0x00020000
typedef enum tagSQObjectType{
OT_NULL = (_RT_NULL|SQOBJECT_CANBEFALSE),
OT_INTEGER = (_RT_INTEGER|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
OT_FLOAT = (_RT_FLOAT|SQOBJECT_NUMERIC|SQOBJECT_CANBEFALSE),
OT_BOOL = (_RT_BOOL|SQOBJECT_CANBEFALSE),
OT_STRING = (_RT_STRING|SQOBJECT_REF_COUNTED),
OT_TABLE = (_RT_TABLE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_ARRAY = (_RT_ARRAY|SQOBJECT_REF_COUNTED),
OT_USERDATA = (_RT_USERDATA|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_CLOSURE = (_RT_CLOSURE|SQOBJECT_REF_COUNTED),
OT_NATIVECLOSURE = (_RT_NATIVECLOSURE|SQOBJECT_REF_COUNTED),
OT_GENERATOR = (_RT_GENERATOR|SQOBJECT_REF_COUNTED),
OT_USERPOINTER = _RT_USERPOINTER,
OT_THREAD = (_RT_THREAD|SQOBJECT_REF_COUNTED) ,
OT_FUNCPROTO = (_RT_FUNCPROTO|SQOBJECT_REF_COUNTED), //internal usage only
OT_CLASS = (_RT_CLASS|SQOBJECT_REF_COUNTED),
OT_INSTANCE = (_RT_INSTANCE|SQOBJECT_REF_COUNTED|SQOBJECT_DELEGABLE),
OT_WEAKREF = (_RT_WEAKREF|SQOBJECT_REF_COUNTED),
OT_OUTER = (_RT_OUTER|SQOBJECT_REF_COUNTED) //internal usage only
}SQObjectType;
#define ISREFCOUNTED(t) (t&SQOBJECT_REF_COUNTED)
typedef union tagSQObjectValue
{
struct SQTable *pTable;
struct SQArray *pArray;
struct SQClosure *pClosure;
struct SQOuter *pOuter;
struct SQGenerator *pGenerator;
struct SQNativeClosure *pNativeClosure;
struct SQString *pString;
struct SQUserData *pUserData;
SQInteger nInteger;
SQFloat fFloat;
SQUserPointer pUserPointer;
struct SQFunctionProto *pFunctionProto;
struct SQRefCounted *pRefCounted;
struct SQDelegable *pDelegable;
struct SQVM *pThread;
struct SQClass *pClass;
struct SQInstance *pInstance;
struct SQWeakRef *pWeakRef;
SQRawObjectVal raw;
}SQObjectValue;
typedef struct tagSQObject
{
SQObjectType _type;
SQObjectValue _unVal;
}SQObject;
typedef struct tagSQMemberHandle{
SQBool _static;
SQInteger _index;
}SQMemberHandle;
typedef struct tagSQStackInfos{
const SQChar* funcname;
const SQChar* source;
SQInteger line;
}SQStackInfos;
typedef struct SQVM* HSQUIRRELVM;
typedef SQObject HSQOBJECT;
typedef SQMemberHandle HSQMEMBERHANDLE;
typedef SQInteger (*SQFUNCTION)(HSQUIRRELVM);
typedef SQInteger (*SQRELEASEHOOK)(SQUserPointer,SQInteger size);
typedef void (*SQCOMPILERERROR)(HSQUIRRELVM,const SQChar * /*desc*/,const SQChar * /*source*/,SQInteger /*line*/,SQInteger /*column*/);
typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
typedef void (*SQDEBUGHOOK)(HSQUIRRELVM /*v*/, SQInteger /*type*/, const SQChar * /*sourcename*/, SQInteger /*line*/, const SQChar * /*funcname*/);
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
typedef struct tagSQRegFunction{
const SQChar *name;
SQFUNCTION f;
SQInteger nparamscheck;
const SQChar *typemask;
}SQRegFunction;
typedef struct tagSQFunctionInfo {
SQUserPointer funcid;
const SQChar *name;
const SQChar *source;
}SQFunctionInfo;
/*vm*/
SQUIRREL_API HSQUIRRELVM sq_open(SQInteger initialstacksize);
SQUIRREL_API HSQUIRRELVM sq_newthread(HSQUIRRELVM friendvm, SQInteger initialstacksize);
SQUIRREL_API void sq_seterrorhandler(HSQUIRRELVM v);
SQUIRREL_API void sq_close(HSQUIRRELVM v);
SQUIRREL_API void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p);
SQUIRREL_API SQUserPointer sq_getforeignptr(HSQUIRRELVM v);
SQUIRREL_API void sq_setprintfunc(HSQUIRRELVM v, SQPRINTFUNCTION printfunc,SQPRINTFUNCTION errfunc);
SQUIRREL_API SQPRINTFUNCTION sq_getprintfunc(HSQUIRRELVM v);
SQUIRREL_API SQPRINTFUNCTION sq_geterrorfunc(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_suspendvm(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
SQUIRREL_API SQInteger sq_getvmstate(HSQUIRRELVM v);
/*compiler*/
SQUIRREL_API SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
SQUIRREL_API SQRESULT sq_compilebuffer(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
SQUIRREL_API void sq_enabledebuginfo(HSQUIRRELVM v, SQBool enable);
SQUIRREL_API void sq_notifyallexceptions(HSQUIRRELVM v, SQBool enable);
SQUIRREL_API void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f);
/*stack operations*/
SQUIRREL_API void sq_push(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_pop(HSQUIRRELVM v,SQInteger nelemstopop);
SQUIRREL_API void sq_poptop(HSQUIRRELVM v);
SQUIRREL_API void sq_remove(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQInteger sq_gettop(HSQUIRRELVM v);
SQUIRREL_API void sq_settop(HSQUIRRELVM v,SQInteger newtop);
SQUIRREL_API SQRESULT sq_reservestack(HSQUIRRELVM v,SQInteger nsize);
SQUIRREL_API SQInteger sq_cmp(HSQUIRRELVM v);
SQUIRREL_API void sq_move(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
/*object creation handling*/
SQUIRREL_API SQUserPointer sq_newuserdata(HSQUIRRELVM v,SQUnsignedInteger size);
SQUIRREL_API void sq_newtable(HSQUIRRELVM v);
SQUIRREL_API void sq_newtableex(HSQUIRRELVM v,SQInteger initialcapacity);
SQUIRREL_API void sq_newarray(HSQUIRRELVM v,SQInteger size);
SQUIRREL_API void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
SQUIRREL_API SQRESULT sq_setparamscheck(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
SQUIRREL_API SQRESULT sq_bindenv(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_pushstring(HSQUIRRELVM v,const SQChar *s,SQInteger len);
SQUIRREL_API void sq_pushfloat(HSQUIRRELVM v,SQFloat f);
SQUIRREL_API void sq_pushinteger(HSQUIRRELVM v,SQInteger n);
SQUIRREL_API void sq_pushbool(HSQUIRRELVM v,SQBool b);
SQUIRREL_API void sq_pushuserpointer(HSQUIRRELVM v,SQUserPointer p);
SQUIRREL_API void sq_pushnull(HSQUIRRELVM v);
SQUIRREL_API SQObjectType sq_gettype(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQInteger sq_getsize(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getbase(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQBool sq_instanceof(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_tostring(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_tobool(HSQUIRRELVM v, SQInteger idx, SQBool *b);
SQUIRREL_API SQRESULT sq_getstring(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQUIRREL_API SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQUIRREL_API SQRESULT sq_getfloat(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
SQUIRREL_API SQRESULT sq_getbool(HSQUIRRELVM v,SQInteger idx,SQBool *b);
SQUIRREL_API SQRESULT sq_getthread(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
SQUIRREL_API SQRESULT sq_getuserpointer(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
SQUIRREL_API SQRESULT sq_getuserdata(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
SQUIRREL_API SQRESULT sq_settypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
SQUIRREL_API SQRESULT sq_gettypetag(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger idx,SQFunctionInfo *fi);
SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
SQUIRREL_API SQRESULT sq_getinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
SQUIRREL_API SQRESULT sq_setclassudsize(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
SQUIRREL_API SQRESULT sq_newclass(HSQUIRRELVM v,SQBool hasbase);
SQUIRREL_API SQRESULT sq_createinstance(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setattributes(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getattributes(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getclass(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API void sq_weakref(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getdefaultdelegate(HSQUIRRELVM v,SQObjectType t);
SQUIRREL_API SQRESULT sq_getmemberhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
SQUIRREL_API SQRESULT sq_getbyhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
SQUIRREL_API SQRESULT sq_setbyhandle(HSQUIRRELVM v,SQInteger idx,HSQMEMBERHANDLE *handle);
/*object manipulation*/
SQUIRREL_API void sq_pushroottable(HSQUIRRELVM v);
SQUIRREL_API void sq_pushregistrytable(HSQUIRRELVM v);
SQUIRREL_API void sq_pushconsttable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_setroottable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_setconsttable(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_newslot(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
SQUIRREL_API SQRESULT sq_deleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_set(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_get(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawget(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawset(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_rawdeleteslot(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_arrayappend(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_arraypop(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQUIRREL_API SQRESULT sq_arrayresize(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
SQUIRREL_API SQRESULT sq_arrayreverse(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_arrayremove(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
SQUIRREL_API SQRESULT sq_arrayinsert(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
SQUIRREL_API SQRESULT sq_setdelegate(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getdelegate(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_clone(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_setfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQUIRREL_API SQRESULT sq_next(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_getweakrefval(HSQUIRRELVM v,SQInteger idx);
SQUIRREL_API SQRESULT sq_clear(HSQUIRRELVM v,SQInteger idx);
/*calls*/
SQUIRREL_API SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
SQUIRREL_API SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
SQUIRREL_API const SQChar *sq_getlocal(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
SQUIRREL_API SQRESULT sq_getcallee(HSQUIRRELVM v);
SQUIRREL_API const SQChar *sq_getfreevariable(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQUIRREL_API SQRESULT sq_throwerror(HSQUIRRELVM v,const SQChar *err);
SQUIRREL_API SQRESULT sq_throwobject(HSQUIRRELVM v);
SQUIRREL_API void sq_reseterror(HSQUIRRELVM v);
SQUIRREL_API void sq_getlasterror(HSQUIRRELVM v);
/*raw object handling*/
SQUIRREL_API SQRESULT sq_getstackobj(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
SQUIRREL_API void sq_pushobject(HSQUIRRELVM v,HSQOBJECT obj);
SQUIRREL_API void sq_addref(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API SQBool sq_release(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API SQUnsignedInteger sq_getrefcount(HSQUIRRELVM v,HSQOBJECT *po);
SQUIRREL_API void sq_resetobject(HSQOBJECT *po);
SQUIRREL_API const SQChar *sq_objtostring(const HSQOBJECT *o);
SQUIRREL_API SQBool sq_objtobool(const HSQOBJECT *o);
SQUIRREL_API SQInteger sq_objtointeger(const HSQOBJECT *o);
SQUIRREL_API SQFloat sq_objtofloat(const HSQOBJECT *o);
SQUIRREL_API SQUserPointer sq_objtouserpointer(const HSQOBJECT *o);
SQUIRREL_API SQRESULT sq_getobjtypetag(const HSQOBJECT *o,SQUserPointer * typetag);
/*GC*/
SQUIRREL_API SQInteger sq_collectgarbage(HSQUIRRELVM v);
SQUIRREL_API SQRESULT sq_resurrectunreachable(HSQUIRRELVM v);
/*serialization*/
SQUIRREL_API SQRESULT sq_writeclosure(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
SQUIRREL_API SQRESULT sq_readclosure(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
/*mem allocation*/
SQUIRREL_API void *sq_malloc(SQUnsignedInteger size);
SQUIRREL_API void *sq_realloc(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
SQUIRREL_API void sq_free(void *p,SQUnsignedInteger size);
/*debug*/
SQUIRREL_API SQRESULT sq_stackinfos(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
SQUIRREL_API void sq_setdebughook(HSQUIRRELVM v);
SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
/*UTILITY MACRO*/
#define sq_isnumeric(o) ((o)._type&SQOBJECT_NUMERIC)
#define sq_istable(o) ((o)._type==OT_TABLE)
#define sq_isarray(o) ((o)._type==OT_ARRAY)
#define sq_isfunction(o) ((o)._type==OT_FUNCPROTO)
#define sq_isclosure(o) ((o)._type==OT_CLOSURE)
#define sq_isgenerator(o) ((o)._type==OT_GENERATOR)
#define sq_isnativeclosure(o) ((o)._type==OT_NATIVECLOSURE)
#define sq_isstring(o) ((o)._type==OT_STRING)
#define sq_isinteger(o) ((o)._type==OT_INTEGER)
#define sq_isfloat(o) ((o)._type==OT_FLOAT)
#define sq_isuserpointer(o) ((o)._type==OT_USERPOINTER)
#define sq_isuserdata(o) ((o)._type==OT_USERDATA)
#define sq_isthread(o) ((o)._type==OT_THREAD)
#define sq_isnull(o) ((o)._type==OT_NULL)
#define sq_isclass(o) ((o)._type==OT_CLASS)
#define sq_isinstance(o) ((o)._type==OT_INSTANCE)
#define sq_isbool(o) ((o)._type==OT_BOOL)
#define sq_isweakref(o) ((o)._type==OT_WEAKREF)
#define sq_type(o) ((o)._type)
/* deprecated */
#define sq_createslot(v,n) sq_newslot(v,n,SQFalse)
#define SQ_OK (0)
#define SQ_ERROR (-1)
#define SQ_FAILED(res) (res<0)
#define SQ_SUCCEEDED(res) (res>=0)
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQUIRREL_H_*/

View File

@@ -1,199 +0,0 @@
//
// SqModule: API used to communicate with and register squirrel modules
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SQ_MODULE_H_)
#define _SQ_MODULE_H_
#include "squirrel.h"
#ifdef __cplusplus
extern "C" {
#endif
/* HSQAPI */
/*
Allows modules to interface with squirrel's C api without linking to the squirrel library
If new functions are added to the Squirrel API, they should be added here too
*/
typedef struct {
/*vm*/
HSQUIRRELVM (*open)(SQInteger initialstacksize);
HSQUIRRELVM (*newthread)(HSQUIRRELVM friendvm, SQInteger initialstacksize);
void (*seterrorhandler)(HSQUIRRELVM v);
void (*close)(HSQUIRRELVM v);
void (*setforeignptr)(HSQUIRRELVM v,SQUserPointer p);
SQUserPointer (*getforeignptr)(HSQUIRRELVM v);
#if SQUIRREL_VERSION_NUMBER >= 300
void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc, SQPRINTFUNCTION);
#else
void (*setprintfunc)(HSQUIRRELVM v, SQPRINTFUNCTION printfunc);
#endif
SQPRINTFUNCTION (*getprintfunc)(HSQUIRRELVM v);
SQRESULT (*suspendvm)(HSQUIRRELVM v);
SQRESULT (*wakeupvm)(HSQUIRRELVM v,SQBool resumedret,SQBool retval,SQBool raiseerror,SQBool throwerror);
SQInteger (*getvmstate)(HSQUIRRELVM v);
/*compiler*/
SQRESULT (*compile)(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,const SQChar *sourcename,SQBool raiseerror);
SQRESULT (*compilebuffer)(HSQUIRRELVM v,const SQChar *s,SQInteger size,const SQChar *sourcename,SQBool raiseerror);
void (*enabledebuginfo)(HSQUIRRELVM v, SQBool enable);
void (*notifyallexceptions)(HSQUIRRELVM v, SQBool enable);
void (*setcompilererrorhandler)(HSQUIRRELVM v,SQCOMPILERERROR f);
/*stack operations*/
void (*push)(HSQUIRRELVM v,SQInteger idx);
void (*pop)(HSQUIRRELVM v,SQInteger nelemstopop);
void (*poptop)(HSQUIRRELVM v);
void (*remove)(HSQUIRRELVM v,SQInteger idx);
SQInteger (*gettop)(HSQUIRRELVM v);
void (*settop)(HSQUIRRELVM v,SQInteger newtop);
#if SQUIRREL_VERSION_NUMBER >= 300
SQRESULT (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
#else
void (*reservestack)(HSQUIRRELVM v,SQInteger nsize);
#endif
SQInteger (*cmp)(HSQUIRRELVM v);
void (*move)(HSQUIRRELVM dest,HSQUIRRELVM src,SQInteger idx);
/*object creation handling*/
SQUserPointer (*newuserdata)(HSQUIRRELVM v,SQUnsignedInteger size);
void (*newtable)(HSQUIRRELVM v);
void (*newarray)(HSQUIRRELVM v,SQInteger size);
void (*newclosure)(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars);
SQRESULT (*setparamscheck)(HSQUIRRELVM v,SQInteger nparamscheck,const SQChar *typemask);
SQRESULT (*bindenv)(HSQUIRRELVM v,SQInteger idx);
void (*pushstring)(HSQUIRRELVM v,const SQChar *s,SQInteger len);
void (*pushfloat)(HSQUIRRELVM v,SQFloat f);
void (*pushinteger)(HSQUIRRELVM v,SQInteger n);
void (*pushbool)(HSQUIRRELVM v,SQBool b);
void (*pushuserpointer)(HSQUIRRELVM v,SQUserPointer p);
void (*pushnull)(HSQUIRRELVM v);
SQObjectType (*gettype)(HSQUIRRELVM v,SQInteger idx);
SQInteger (*getsize)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getbase)(HSQUIRRELVM v,SQInteger idx);
SQBool (*instanceof)(HSQUIRRELVM v);
#if SQUIRREL_VERSION_NUMBER >= 300
SQRESULT (*tostring)(HSQUIRRELVM v,SQInteger idx);
#else
void (*tostring)(HSQUIRRELVM v,SQInteger idx);
#endif
void (*tobool)(HSQUIRRELVM v, SQInteger idx, SQBool *b);
SQRESULT (*getstring)(HSQUIRRELVM v,SQInteger idx,const SQChar **c);
SQRESULT (*getinteger)(HSQUIRRELVM v,SQInteger idx,SQInteger *i);
SQRESULT (*getfloat)(HSQUIRRELVM v,SQInteger idx,SQFloat *f);
SQRESULT (*getbool)(HSQUIRRELVM v,SQInteger idx,SQBool *b);
SQRESULT (*getthread)(HSQUIRRELVM v,SQInteger idx,HSQUIRRELVM *thread);
SQRESULT (*getuserpointer)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p);
SQRESULT (*getuserdata)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *p,SQUserPointer *typetag);
SQRESULT (*settypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer typetag);
SQRESULT (*gettypetag)(HSQUIRRELVM v,SQInteger idx,SQUserPointer *typetag);
void (*setreleasehook)(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook);
SQChar* (*getscratchpad)(HSQUIRRELVM v,SQInteger minsize);
SQRESULT (*getclosureinfo)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
SQRESULT (*setnativeclosurename)(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
SQRESULT (*setinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
SQRESULT (*getinstanceup)(HSQUIRRELVM v, SQInteger idx, SQUserPointer *p,SQUserPointer typetag);
SQRESULT (*setclassudsize)(HSQUIRRELVM v, SQInteger idx, SQInteger udsize);
SQRESULT (*newclass)(HSQUIRRELVM v,SQBool hasbase);
SQRESULT (*createinstance)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*setattributes)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getattributes)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getclass)(HSQUIRRELVM v,SQInteger idx);
void (*weakref)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getdefaultdelegate)(HSQUIRRELVM v,SQObjectType t);
/*object manipulation*/
void (*pushroottable)(HSQUIRRELVM v);
void (*pushregistrytable)(HSQUIRRELVM v);
void (*pushconsttable)(HSQUIRRELVM v);
SQRESULT (*setroottable)(HSQUIRRELVM v);
SQRESULT (*setconsttable)(HSQUIRRELVM v);
SQRESULT (*newslot)(HSQUIRRELVM v, SQInteger idx, SQBool bstatic);
SQRESULT (*deleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*set)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*get)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawget)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawset)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*rawdeleteslot)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*arrayappend)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*arraypop)(HSQUIRRELVM v,SQInteger idx,SQBool pushval);
SQRESULT (*arrayresize)(HSQUIRRELVM v,SQInteger idx,SQInteger newsize);
SQRESULT (*arrayreverse)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*arrayremove)(HSQUIRRELVM v,SQInteger idx,SQInteger itemidx);
SQRESULT (*arrayinsert)(HSQUIRRELVM v,SQInteger idx,SQInteger destpos);
SQRESULT (*setdelegate)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getdelegate)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*clone)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*setfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQRESULT (*next)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*getweakrefval)(HSQUIRRELVM v,SQInteger idx);
SQRESULT (*clear)(HSQUIRRELVM v,SQInteger idx);
/*calls*/
SQRESULT (*call)(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror);
SQRESULT (*resume)(HSQUIRRELVM v,SQBool retval,SQBool raiseerror);
const SQChar* (*getlocal)(HSQUIRRELVM v,SQUnsignedInteger level,SQUnsignedInteger idx);
const SQChar* (*getfreevariable)(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger nval);
SQRESULT (*throwerror)(HSQUIRRELVM v,const SQChar *err);
void (*reseterror)(HSQUIRRELVM v);
void (*getlasterror)(HSQUIRRELVM v);
/*raw object handling*/
SQRESULT (*getstackobj)(HSQUIRRELVM v,SQInteger idx,HSQOBJECT *po);
void (*pushobject)(HSQUIRRELVM v,HSQOBJECT obj);
void (*addref)(HSQUIRRELVM v,HSQOBJECT *po);
SQBool (*release)(HSQUIRRELVM v,HSQOBJECT *po);
void (*resetobject)(HSQOBJECT *po);
const SQChar* (*objtostring)(const HSQOBJECT *o);
SQBool (*objtobool)(const HSQOBJECT *o);
SQInteger (*objtointeger)(const HSQOBJECT *o);
SQFloat (*objtofloat)(const HSQOBJECT *o);
SQRESULT (*getobjtypetag)(const HSQOBJECT *o,SQUserPointer * typetag);
/*GC*/
SQInteger (*collectgarbage)(HSQUIRRELVM v);
/*serialization*/
SQRESULT (*writeclosure)(HSQUIRRELVM vm,SQWRITEFUNC writef,SQUserPointer up);
SQRESULT (*readclosure)(HSQUIRRELVM vm,SQREADFUNC readf,SQUserPointer up);
/*mem allocation*/
void* (*malloc)(SQUnsignedInteger size);
void* (*realloc)(void* p,SQUnsignedInteger oldsize,SQUnsignedInteger newsize);
void (*free)(void *p,SQUnsignedInteger size);
/*debug*/
SQRESULT (*stackinfos)(HSQUIRRELVM v,SQInteger level,SQStackInfos *si);
void (*setdebughook)(HSQUIRRELVM v);
} sq_api;
typedef sq_api* HSQAPI;
#ifdef __cplusplus
} /*extern "C"*/
#endif
#endif /*_SQ_MODULE_H_*/

View File

@@ -1,41 +0,0 @@
//
// Sqrat: Squirrel C++ Binding Utility
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_MAIN_H_)
#define _SCRAT_MAIN_H_
#include <squirrel.h>
#include "sqrat/sqratTable.h"
#include "sqrat/sqratClass.h"
#include "sqrat/sqratFunction.h"
#include "sqrat/sqratConst.h"
#include "sqrat/sqratUtil.h"
#include "sqrat/sqratScript.h"
#include "sqrat/sqratArray.h"
#endif

View File

@@ -1,134 +0,0 @@
//
// SqratAllocator: Custom Class Allocation/Deallocation
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_ALLOCATOR_H_)
#define _SCRAT_ALLOCATOR_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
namespace Sqrat {
//
// DefaultAllocator
//
template<class C>
class DefaultAllocator {
public:
static SQInteger New(HSQUIRRELVM vm) {
C* instance = new C();
sq_setinstanceup(vm, 1, instance);
sq_setreleasehook(vm, 1, &Delete);
return 0;
}
static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
C* instance = new C(*static_cast<const C*>(value));
sq_setinstanceup(vm, idx, instance);
sq_setreleasehook(vm, idx, &Delete);
return 0;
}
static SQInteger Delete(SQUserPointer ptr, SQInteger size) {
C* instance = reinterpret_cast<C*>(ptr);
delete instance;
return 0;
}
};
//
// NoConstructorAllocator
//
class NoConstructor {
public:
static SQInteger New(HSQUIRRELVM) {
return 0;
}
static SQInteger Copy(HSQUIRRELVM, SQInteger, const void*) {
return 0;
}
static SQInteger Delete(SQUserPointer, SQInteger) {
return 0;
}
};
//
// CopyOnly
//
template<class C>
class CopyOnly {
public:
static SQInteger New(HSQUIRRELVM) {
return 0;
}
static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
C* instance = new C(*static_cast<const C*>(value));
sq_setinstanceup(vm, idx, instance);
sq_setreleasehook(vm, idx, &Delete);
return 0;
}
static SQInteger Delete(SQUserPointer ptr, SQInteger size) {
void* instance = reinterpret_cast<C*>(ptr);
delete instance;
return 0;
}
};
//
// NoCopy
//
template<class C>
class NoCopy {
public:
static SQInteger New(HSQUIRRELVM vm) {
C* instance = new C();
sq_setinstanceup(vm, 1, instance);
sq_setreleasehook(vm, 1, &Delete);
return 0;
}
static SQInteger Copy(HSQUIRRELVM vm, SQInteger idx, const void* value) {
return 0;
}
static SQInteger Delete(SQUserPointer ptr, SQInteger size) {
C* instance = reinterpret_cast<C*>(ptr);
delete instance;
return 0;
}
};
}
#endif

View File

@@ -1,210 +0,0 @@
//
// SqratArray: Array Binding
//
//
// Copyright 2011 Alston Chen
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_ARRAY_H_)
#define _SCRAT_ARRAY_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratFunction.h"
#include "sqratGlobalMethods.h"
namespace Sqrat {
class ArrayBase : public Object {
public:
ArrayBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
}
ArrayBase(const Object& obj) : Object(obj) {
}
// Bind a Table or Class to the Array (Can be used to facilitate Namespaces)
// Note: Bind cannot be called "inline" like other functions because it introduces order-of-initialization bugs.
void Bind(const SQInteger index, Object& obj) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
sq_pushobject(vm, obj.GetObject());
sq_set(vm, -3);
sq_pop(vm,1); // pop array
}
// Bind a raw Squirrel closure to the Array
ArrayBase& SquirrelFunc(const SQInteger index, SQFUNCTION func) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
sq_newclosure(vm, func, 0);
sq_set(vm, -3);
sq_pop(vm,1); // pop array
return *this;
}
//
// Variable Binding
//
template<class V>
ArrayBase& SetValue(const SQInteger index, const V& val) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
PushVar(vm, val);
sq_set(vm, -3);
sq_pop(vm,1); // pop array
return *this;
}
template<class V>
ArrayBase& SetInstance(const SQInteger index, V* val) {
BindInstance<V>(index, false);
return *this;
}
template<class F>
ArrayBase& Func(const SQInteger index, F method) {
BindFunc(index, &method, sizeof(method), SqGlobalFunc(method));
return *this;
}
//template<class F>
//ArrayBase& Overload(const SQChar* name, F method) {
// BindOverload(name, &method, sizeof(method), SqGlobalFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
// return *this;
//}
//
// Function Calls
//
Function GetFunction(const SQInteger index) {
HSQOBJECT funcObj;
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pushnull(vm);
}
sq_getstackobj(vm, -1, &funcObj);
Function ret(vm, GetObject(), funcObj);
sq_pop(vm, 2);
return ret;
}
//
// Array manipulation
//
template<class V>
ArrayBase& Append(const V& val) {
sq_pushobject(vm, GetObject());
PushVar(vm, val);
sq_arrayappend(vm, -2);
sq_pop(vm,1); // pop array
return *this;
}
template<class V>
ArrayBase& Append(V* val) {
sq_pushobject(vm, GetObject());
PushVar(vm, val);
sq_arrayappend(vm, -2);
sq_pop(vm,1); // pop array
return *this;
}
template<class V>
ArrayBase& Insert(const SQInteger destpos, const V& val) {
sq_pushobject(vm, GetObject());
PushVar(vm, val);
sq_arrayinsert(vm, -2, destpos);
sq_pop(vm,1); // pop array
return *this;
}
template<class V>
ArrayBase& Insert(const SQInteger destpos, V* val) {
sq_pushobject(vm, GetObject());
PushVar(vm, val);
sq_arrayinsert(vm, -2, destpos);
sq_pop(vm,1); // pop array
return *this;
}
Object Pop() {
HSQOBJECT slotObj;
sq_pushobject(vm, GetObject());
if(SQ_FAILED(sq_arraypop(vm, -1, true))) {
sq_pop(vm, 1);
return Object(); // Return a NULL object
} else {
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm);
sq_pop(vm, 2);
return ret;
}
}
ArrayBase& Remove(const SQInteger itemidx) {
sq_pushobject(vm, GetObject());
sq_arrayremove(vm, -1, itemidx);
sq_pop(vm,1); // pop array
return *this;
}
ArrayBase& Resize(const SQInteger newsize) {
sq_pushobject(vm, GetObject());
sq_arrayresize(vm, -1, newsize);
sq_pop(vm,1); // pop array
return *this;
}
ArrayBase& Reverse() {
sq_pushobject(vm, GetObject());
sq_arrayreverse(vm, -1);
sq_pop(vm,1); // pop array
return *this;
}
};
class Array : public ArrayBase {
public:
Array(HSQUIRRELVM v = DefaultVM::Get(), const SQInteger size = 0) : ArrayBase(v) {
sq_newarray(vm, size);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm,1);
}
Array(const Object& obj) : ArrayBase(obj) {
}
};
}
#endif

View File

@@ -1,415 +0,0 @@
//
// SqratClass: Class Binding
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_CLASS_H_)
#define _SCRAT_CLASS_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratClassType.h"
#include "sqratMemberMethods.h"
#include "sqratAllocator.h"
namespace Sqrat
{
/**
@tparam C class type to expose
@tparam A allocator to use when instantiating and destroying class instances in Squirrel
@remarks
DefaultAllocator<C> is used if no allocator is specified. This should be sufficent for most classes
but if specific behavior is desired it can be overridden. If the class should not be instantiated from
Squirrel the NoConstructor allocator may be used.
*/
/// Exposes a C++ class to Squirrel
template<class C, class A = DefaultAllocator<C> >
class Class : public Object
{
public:
/**
@param v Squirrel virtual machine to bind to
*/
/// Constructor
Class(HSQUIRRELVM v = DefaultVM::Get(), bool createClass = true) : Object(v, false) {
if(createClass && !ClassType<C>::Initialized(v)) {
HSQOBJECT& classObj = ClassType<C>::ClassObject(v);
sq_resetobject(&classObj);
sq_newclass(vm, false);
sq_getstackobj(vm, -1, &classObj);
sq_addref(vm, &classObj); // must addref before the pop!
sq_pop(vm, 1);
InitClass();
ClassType<C>::Initialized(v) = true;
}
}
~Class() {
/*ClassType<C>::deleteClassTypeData(vm);*/
/* it seems the original design by Tojo was that ClassType objects are static
so they presist with the lifetime of the program; so we cannot delete the
ClassType object here */
}
/// Get the Squirrel Object for this Class (const)
virtual HSQOBJECT GetObject() const {
return ClassType<C>::ClassObject(vm);
}
/// Get the Squirrel Object for this Class (ref)
virtual HSQOBJECT& GetObject() {
return ClassType<C>::ClassObject(vm);
}
public:
//
// Variable Binding
//
/**
@param name name of the static slot
@param var value to assign
*/
/// Assign a static class slot a value
template<class V>
Class& SetStaticValue(const SQChar* name, const V& val) {
BindValue<V>(name, val, true);
return *this;
}
/**
@param name name of the slot
@param var value to assign
*/
/// Assign a class slot a value
template<class V>
Class& SetValue(const SQChar* name, const V& val) {
BindValue<V>(name, val, false);
return *this;
}
/**
@param name name of the variable as it will appear in Squirrel
@param var variable to bind
*/
/// Bind a class variable
template<class V>
Class& Var(const SQChar* name, V C::* var) {
// Add the getter
BindAccessor(name, &var, sizeof(var), &sqDefaultGet<C, V>, ClassType<C>::GetTable(vm));
// Add the setter
BindAccessor(name, &var, sizeof(var), &sqDefaultSet<C, V>, ClassType<C>::SetTable(vm));
return *this;
}
/// Bind a class property (variable accessed via a setter and getter)
template<class V>
Class& Prop(const SQChar* name, V (C::*getMethod)() const, void (C::*setMethod)(const V&)) {
if(getMethod != NULL) {
// Add the getter
BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberFunc(getMethod), ClassType<C>::GetTable(vm));
}
if(setMethod != NULL) {
// Add the setter
BindAccessor(name, &setMethod, sizeof(setMethod), SqMemberFunc(setMethod), ClassType<C>::SetTable(vm));
}
return *this;
}
/// Bind a class property (variable accessed via a setter and getter)
template<class V>
Class& Prop(const SQChar* name, V (C::*getMethod)(), void (C::*setMethod)(V)) {
if(getMethod != NULL) {
// Add the getter
BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberFunc(getMethod), ClassType<C>::GetTable(vm));
}
if(setMethod != NULL) {
// Add the setter
BindAccessor(name, &setMethod, sizeof(setMethod), SqMemberFunc(setMethod), ClassType<C>::SetTable(vm));
}
return *this;
}
/// Bind a read only class property (variable accessed via a getter)
template<class V>
Class& Prop(const SQChar* name, V (C::*getMethod)() const) {
// Add the getter
BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberFunc(getMethod), ClassType<C>::GetTable(vm));
return *this;
}
/// Bind a read only class property (variable accessed via a getter)
template<class V>
Class& Prop(const SQChar* name, V (C::*getMethod)()) {
// Add the getter
BindAccessor(name, &getMethod, sizeof(getMethod), SqMemberFunc(getMethod), ClassType<C>::GetTable(vm));
return *this;
}
// TODO: Handle static instance vars
//
// Function Binding
//
template<class F>
Class& Func(const SQChar* name, F method) {
BindFunc(name, &method, sizeof(method), SqMemberFunc(method));
return *this;
}
template<class F>
Class& Overload(const SQChar* name, F method) {
BindOverload(name, &method, sizeof(method), SqMemberFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
return *this;
}
template<class F>
Class& GlobalFunc(const SQChar* name, F method) {
BindFunc(name, &method, sizeof(method), SqMemberGlobalFunc(method));
return *this;
}
template<class F>
Class& StaticFunc(const SQChar* name, F method) {
BindFunc(name, &method, sizeof(method), SqGlobalFunc(method));
return *this;
}
template<class F>
Class& SquirrelFunc(const SQChar* name, SQFUNCTION func) {
sq_pushobject(vm, ClassType<C>::ClassObject(vm));
sq_pushstring(vm, name, -1);
sq_newclosure(vm, func, 0);
sq_newslot(vm, -3, false);
sq_pop(vm, 1); // pop table
return *this;
}
//
// Function Calls
//
Function GetFunction(const SQChar* name) {
HSQOBJECT funcObj;
sq_pushobject(vm, ClassType<C>::ClassObject(vm));
sq_pushstring(vm, name, -1);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pushnull(vm);
}
sq_getstackobj(vm, -1, &funcObj);
sq_pop(vm, 2);
return Function(vm, ClassType<C>::ClassObject(vm), funcObj);
}
protected:
static SQInteger ClassWeakref(HSQUIRRELVM vm) {
sq_weakref(vm, -1);
return 1;
}
// Initialize the required data structure for the class
void InitClass() {
ClassType<C>::CopyFunc(vm) = &A::Copy;
// push the class
sq_pushobject(vm, ClassType<C>::ClassObject(vm));
// add the default constructor
sq_pushstring(vm,_SC("constructor"), -1);
sq_newclosure(vm, &A::New, 0);
sq_newslot(vm, -3, false);
// add the set table (static)
HSQOBJECT& setTable = ClassType<C>::SetTable(vm);
sq_resetobject(&setTable);
sq_pushstring(vm,_SC("__setTable"), -1);
sq_newtable(vm);
sq_getstackobj(vm, -1, &setTable);
sq_addref(vm, &setTable);
sq_newslot(vm, -3, true);
// add the get table (static)
HSQOBJECT& getTable = ClassType<C>::GetTable(vm);
sq_resetobject(&getTable);
sq_pushstring(vm,_SC("__getTable"), -1);
sq_newtable(vm);
sq_getstackobj(vm, -1, &getTable);
sq_addref(vm, &getTable);
sq_newslot(vm, -3, true);
// override _set
sq_pushstring(vm, _SC("_set"), -1);
sq_pushobject(vm, setTable); // Push the set table as a free variable
sq_newclosure(vm, &sqVarSet, 1);
sq_newslot(vm, -3, false);
// override _get
sq_pushstring(vm, _SC("_get"), -1);
sq_pushobject(vm, getTable); // Push the get table as a free variable
sq_newclosure(vm, &sqVarGet, 1);
sq_newslot(vm, -3, false);
// add weakref (apparently not provided by default)
sq_pushstring(vm, _SC("weakref"), -1);
sq_newclosure(vm, &Class::ClassWeakref, 0);
sq_newslot(vm, -3, false);
// pop the class
sq_pop(vm, 1);
}
// Helper function used to bind getters and setters
inline void BindAccessor(const SQChar* name, void* var, size_t varSize, SQFUNCTION func, HSQOBJECT table) {
// Push the get or set table
sq_pushobject(vm, table);
sq_pushstring(vm, name, -1);
// Push the variable offset as a free variable
SQUserPointer varPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(varSize));
memcpy(varPtr, var, varSize);
// Create the accessor function
sq_newclosure(vm, func, 1);
// Add the accessor to the table
sq_newslot(vm, -3, false);
// Pop get/set table
sq_pop(vm, 1);
}
};
/**
@tparam C class type to expose
@tparam B base class type (must already be bound)
@tparam A allocator to use when instantiating and destroying class instances in Squirrel
@remarks
DefaultAllocator<C> is used if no allocator is specified. This should be sufficent for most classes
but if specific behavior is desired it can be overridden. If the class should not be instantiated from
Squirrel the NoConstructor allocator may be used.
@remarks
Classes in Squirrel are single-inheritance only, and as such Sqrat only allows for single inheritance as well
*/
/// Exposes a C++ class with a base class to Squirrel
template<class C, class B, class A = DefaultAllocator<C> >
class DerivedClass : public Class<C, A>
{
public:
DerivedClass(HSQUIRRELVM v = DefaultVM::Get()) : Class<C, A>(v, false) {
if(!ClassType<C>::Initialized(v)) {
HSQOBJECT& classObj = ClassType<C>::ClassObject(v);
sq_resetobject(&classObj);
sq_pushobject(v, ClassType<B>::ClassObject(v));
sq_newclass(v, true);
sq_getstackobj(v, -1, &classObj);
sq_addref(v, &classObj); // must addref before the pop!
sq_pop(v, 1);
InitDerivedClass(v);
ClassType<C>::Initialized(v) = true;
}
}
protected:
void InitDerivedClass(HSQUIRRELVM vm) {
ClassType<C>::CopyFunc(vm) = &A::Copy;
// push the class
sq_pushobject(vm, ClassType<C>::ClassObject(vm));
// add the default constructor
sq_pushstring(vm,_SC("constructor"), -1);
sq_newclosure(vm, &A::New, 0);
sq_newslot(vm, -3, false);
// clone the base classes set table (static)
HSQOBJECT& setTable = ClassType<C>::SetTable(vm);
sq_resetobject(&setTable);
sq_pushobject(vm, ClassType<B>::SetTable(vm));
sq_pushstring(vm,_SC("__setTable"), -1);
sq_clone(vm, -2);
sq_remove(vm, -3);
sq_getstackobj(vm, -1, &setTable);
sq_addref(vm, &setTable);
sq_newslot(vm, -3, true);
// clone the base classes get table (static)
HSQOBJECT& getTable = ClassType<C>::GetTable(vm);
sq_resetobject(&getTable);
sq_pushobject(vm, ClassType<B>::GetTable(vm));
sq_pushstring(vm,_SC("__getTable"), -1);
sq_clone(vm, -2);
sq_remove(vm, -3);
sq_getstackobj(vm, -1, &getTable);
sq_addref(vm, &getTable);
sq_newslot(vm, -3, true);
// override _set
sq_pushstring(vm, _SC("_set"), -1);
sq_pushobject(vm, setTable); // Push the set table as a free variable
sq_newclosure(vm, sqVarSet, 1);
sq_newslot(vm, -3, false);
// override _get
sq_pushstring(vm, _SC("_get"), -1);
sq_pushobject(vm, getTable); // Push the get table as a free variable
sq_newclosure(vm, sqVarGet, 1);
sq_newslot(vm, -3, false);
// add weakref (apparently not provided by default)
sq_pushstring(vm, _SC("weakref"), -1);
sq_newclosure(vm, &Class<C, A>::ClassWeakref, 0);
sq_newslot(vm, -3, false);
// pop the class
sq_pop(vm, 1);
}
};
}
#endif

View File

@@ -1,126 +0,0 @@
//
// SqratClassType: Type Translators
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_CLASSTYPE_H_)
#define _SCRAT_CLASSTYPE_H_
#include <squirrel.h>
#include <map>
namespace Sqrat
{
//
// ClassType
//
// Get the Copy Function for this Class
typedef SQInteger (*COPYFUNC)(HSQUIRRELVM, SQInteger, const void*);
struct ClassTypeData {
bool initialized;
HSQOBJECT classObj;
HSQOBJECT getTable;
HSQOBJECT setTable;
COPYFUNC copyFunc;
ClassTypeData(): initialized(false) {}
};
template<class C>
struct ClassType {
static std::map< HSQUIRRELVM, ClassTypeData > s_classTypeDataMap;
static inline ClassTypeData& getClassTypeData(HSQUIRRELVM vm) {
//TODO: use mutex to lock s_classTypeDataMap in multithreaded environment
return s_classTypeDataMap[vm];
}
static inline bool hasClassTypeData(HSQUIRRELVM vm) {
//TODO: use mutex to lock s_classTypeDataMap in multithreaded environment
return (s_classTypeDataMap.find(vm) != s_classTypeDataMap.end());
}
static inline void deleteClassTypeData(HSQUIRRELVM vm) {
//TODO: use mutex to lock s_classTypeDataMap in multithreaded environment
std::map< HSQUIRRELVM, ClassTypeData >::iterator it = s_classTypeDataMap.find(vm);
if(it != s_classTypeDataMap.end()) {
s_classTypeDataMap.erase(it);
}
}
// Get the Squirrel Object for this Class
static inline HSQOBJECT& ClassObject(HSQUIRRELVM vm) {
return getClassTypeData(vm).classObj;
}
// Get the Get Table for this Class
static inline HSQOBJECT& GetTable(HSQUIRRELVM vm) {
return getClassTypeData(vm).getTable;
}
// Get the Set Table for this Class
static inline HSQOBJECT& SetTable(HSQUIRRELVM vm) {
return getClassTypeData(vm).setTable;
}
static inline COPYFUNC& CopyFunc(HSQUIRRELVM vm) {
return getClassTypeData(vm).copyFunc;
}
static inline bool& Initialized(HSQUIRRELVM vm) {
return getClassTypeData(vm).initialized;
}
static void PushInstance(HSQUIRRELVM vm, C* ptr) {
sq_pushobject(vm, ClassObject(vm));
sq_createinstance(vm, -1);
sq_remove(vm, -2);
sq_setinstanceup(vm, -1, ptr);
}
static void PushInstanceCopy(HSQUIRRELVM vm, C& value) {
sq_pushobject(vm, ClassObject(vm));
sq_createinstance(vm, -1);
sq_remove(vm, -2);
CopyFunc(vm)(vm, -1, &value);
}
static C* GetInstance(HSQUIRRELVM vm, SQInteger idx) {
C* ptr = NULL;
sq_getinstanceup(vm, idx, (SQUserPointer*)&ptr, NULL);
return ptr;
}
};
template<class C>
std::map< HSQUIRRELVM, ClassTypeData > ClassType<C>::s_classTypeDataMap;
}
#endif

View File

@@ -1,120 +0,0 @@
//
// SqratConst: Constant and Enumeration Binding
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_CONST_H_)
#define _SCRAT_CONST_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
namespace Sqrat {
//
// Enumerations
//
class Enumeration : public Object {
public:
Enumeration(HSQUIRRELVM v = DefaultVM::Get(), bool createTable = true) : Object(v, false) {
if(createTable) {
sq_newtable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm,1);
}
}
//
// Bind Constants
//
virtual Enumeration& Const(const SQChar* name, const int val) {
BindValue<int>(name, val, false);
return *this;
}
virtual Enumeration& Const(const SQChar* name, const float val) {
BindValue<float>(name, val, false);
return *this;
}
virtual Enumeration& Const(const SQChar* name, const SQChar* val) {
BindValue<const SQChar*>(name, val, false);
return *this;
}
};
//
// Constants
//
class ConstTable : public Enumeration {
public:
ConstTable(HSQUIRRELVM v = DefaultVM::Get()) : Enumeration(v, false) {
sq_pushconsttable(vm);
sq_getstackobj(vm,-1, &obj);
sq_pop(v,1); // No addref needed, since the consttable is always around
}
//
// Bind Constants
//
virtual ConstTable& Const(const SQChar* name, const int val) {
Enumeration::Const(name, val);
return *this;
}
virtual ConstTable& Const(const SQChar* name, const float val) {
Enumeration::Const(name, val);
return *this;
}
virtual ConstTable& Const(const SQChar* name, const SQChar* val) {
Enumeration::Const(name, val);
return *this;
}
//
// Bind Enumerations
//
ConstTable& Enum(const SQChar* name, Enumeration& en) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
sq_pushobject(vm, en.GetObject());
sq_newslot(vm, -3, false);
sq_pop(vm,1); // pop table
return *this;
}
};
}
#endif

View File

@@ -1,751 +0,0 @@
//
// SqObject: Referenced Squirrel Object Wrapper
//
//
// Copyright (c) 2009 Brandon Jones
// Copyirght 2011 Li-Cheng (Andy) Tai
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_SQFUNC_H_)
#define _SCRAT_SQFUNC_H_
#include <squirrel.h>
#include "sqratObject.h"
namespace Sqrat {
class Function {
friend class TableBase;
friend class Table;
friend class ArrayBase;
friend struct Var<Function>;
private:
HSQUIRRELVM vm;
HSQOBJECT env, obj;
Function(HSQUIRRELVM v, HSQOBJECT e, HSQOBJECT o) : vm(v), env(e), obj(o) {
sq_addref(vm, &env);
sq_addref(vm, &obj);
}
public:
Function() {
sq_resetobject(&env);
sq_resetobject(&obj);
}
Function(const Function& sf) : vm(sf.vm), env(sf.env), obj(sf.obj) {
sq_addref(vm, &env);
sq_addref(vm, &obj);
}
Function(const Object& e, const SQChar* slot) : vm(e.GetVM()), env(e.GetObject()) {
sq_addref(vm, &env);
Object so = e.GetSlot(slot);
obj = so.GetObject();
sq_addref(vm, &obj);
}
~Function() {
Release();
}
Function& operator=(const Function& sf) {
Release();
vm = sf.vm;
env = sf.env;
obj = sf.obj;
sq_addref(vm, &env);
sq_addref(vm, &obj);
return *this;
}
bool IsNull() {
return sq_isnull(obj);
}
HSQOBJECT& GetEnv() {
return env;
}
HSQOBJECT& GetFunc() {
return obj;
}
HSQUIRRELVM& GetVM() {
return vm;
}
void Release() {
if(!IsNull()) {
sq_release(vm, &env);
sq_release(vm, &obj);
sq_resetobject(&env);
sq_resetobject(&obj);
}
}
template <class R>
R Evaluate() {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
sq_call(vm, 1, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1>
R Evaluate(A1 a1) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
sq_call(vm, 2, true, ErrorHandling::IsEnabled());
Var<R> ret(vm, -1);
sq_pop(vm, 2);
return ret.value;
}
template <class R, class A1, class A2>
R Evaluate(A1 a1, A2 a2) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
sq_call(vm, 3, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3>
R Evaluate(A1 a1, A2 a2, A3 a3) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
sq_call(vm, 4, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
sq_call(vm, 5, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
sq_call(vm, 6, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
sq_call(vm, 7, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
sq_call(vm, 8, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
sq_call(vm, 9, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
sq_call(vm, 10, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
sq_call(vm, 11, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
sq_call(vm, 12, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
sq_call(vm, 13, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
PushVar(vm, a13);
sq_call(vm, 14, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
R Evaluate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13, A14 a14) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
PushVar(vm, a13);
PushVar(vm, a14);
sq_call(vm, 15, true, ErrorHandling::IsEnabled());
R ret = Var<R>(vm, -1).value;
sq_pop(vm, 2);
return ret;
}
//
// void returns
//
void Execute() {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
sq_call(vm, 1, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1>
void Execute(A1 a1) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
sq_call(vm, 2, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2>
void Execute(A1 a1, A2 a2) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
sq_call(vm, 3, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3>
void Execute(A1 a1, A2 a2, A3 a3) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
sq_call(vm, 4, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
sq_call(vm, 5, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
sq_call(vm, 6, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
sq_call(vm, 7, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
sq_call(vm, 8, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
sq_call(vm, 9, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
sq_call(vm, 10, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
sq_call(vm, 11, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
sq_call(vm, 12, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
sq_call(vm, 13, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
PushVar(vm, a13);
sq_call(vm, 14, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
void Execute(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13, A14 a14) {
sq_pushobject(vm, obj);
sq_pushobject(vm, env);
PushVar(vm, a1);
PushVar(vm, a2);
PushVar(vm, a3);
PushVar(vm, a4);
PushVar(vm, a5);
PushVar(vm, a6);
PushVar(vm, a7);
PushVar(vm, a8);
PushVar(vm, a9);
PushVar(vm, a10);
PushVar(vm, a11);
PushVar(vm, a12);
PushVar(vm, a13);
PushVar(vm, a14);
sq_call(vm, 15, false, ErrorHandling::IsEnabled());
sq_pop(vm, 1);
}
//
// Operator overloads for ease of use (calls Execute)
//
void operator()() {
Execute();
}
template <class A1>
void operator()(A1 a1) {
Execute(a1);
}
template <class A1, class A2>
void operator()(A1 a1, A2 a2) {
Execute(a1, a2);
}
template <class A1, class A2, class A3>
void operator()(A1 a1, A2 a2, A3 a3) {
Execute(a1, a2, a3);
}
template <class A1, class A2, class A3, class A4>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4) {
Execute(a1, a2, a3, a4);
}
template <class A1, class A2, class A3, class A4, class A5>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5) {
Execute(a1, a2, a3, a4, a5);
}
template <class A1, class A2, class A3, class A4, class A5, class A6>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6) {
Execute(a1, a2, a3, a4, a5, a6);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7) {
Execute(a1, a2, a3, a4, a5, a6, a7);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
}
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
void operator()(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13, A14 a14) {
Execute(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
}
};
//
// Overridden Getter/Setter
//
template<>
struct Var<Function> {
Function value;
Var(HSQUIRRELVM vm, SQInteger idx) {
HSQOBJECT sqEnv;
HSQOBJECT sqValue;
sq_getstackobj(vm, 1, &sqEnv);
sq_getstackobj(vm, idx, &sqValue);
value = Function(vm, sqEnv, sqValue);
}
static void push(HSQUIRRELVM vm, Function& value) {
sq_pushobject(vm, value.GetFunc());
}
};
}
#endif

View File

@@ -1,835 +0,0 @@
//
// SqratGlobalMethods: Global Methods
//
//
// Copyright (c) 2009 Brandon Jones
// Copyirght 2011 Li-Cheng (Andy) Tai
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_GLOBAL_METHODS_H_)
#define _SCRAT_GLOBAL_METHODS_H_
#include <squirrel.h>
#include "sqratTypes.h"
namespace Sqrat {
//
// Squirrel Global Functions
//
template <class R>
class SqGlobal {
public:
// Arg Count 0
static SQInteger Func0(HSQUIRRELVM vm) {
typedef R (*M)();
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)();
PushVar(vm, ret);
return 1;
}
// Arg Count 1
template <class A1, SQInteger startIdx>
static SQInteger Func1(HSQUIRRELVM vm) {
typedef R (*M)(A1);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 2
template <class A1, class A2, SQInteger startIdx>
static SQInteger Func2(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 3
template <class A1, class A2, class A3, SQInteger startIdx>
static SQInteger Func3(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 4
template <class A1, class A2, class A3, class A4, SQInteger startIdx>
static SQInteger Func4(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 5
template <class A1, class A2, class A3, class A4, class A5, SQInteger startIdx>
static SQInteger Func5(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 6
template <class A1, class A2, class A3, class A4, class A5, class A6, SQInteger startIdx>
static SQInteger Func6(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 7
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, SQInteger startIdx>
static SQInteger Func7(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 8
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, SQInteger startIdx>
static SQInteger Func8(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 9
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, SQInteger startIdx>
static SQInteger Func9(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 10
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, SQInteger startIdx>
static SQInteger Func10(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 11
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, SQInteger startIdx>
static SQInteger Func11(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 12
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, SQInteger startIdx>
static SQInteger Func12(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 13
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, SQInteger startIdx>
static SQInteger Func13(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value,
Var<A13>(vm, startIdx + 12).value
);
PushVar(vm, ret);
return 1;
}
// Arg Count 14
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14, SQInteger startIdx>
static SQInteger Func14(HSQUIRRELVM vm) {
typedef R (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
R ret = (*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value,
Var<A13>(vm, startIdx + 12).value,
Var<A14>(vm, startIdx + 13).value
);
PushVar(vm, ret);
return 1;
}
};
//
// void return specialization
//
template <>
class SqGlobal<void> {
public:
// Arg Count 0
static SQInteger Func0(HSQUIRRELVM vm) {
typedef void (*M)();
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)();
return 0;
}
// Arg Count 1
template <class A1, SQInteger startIdx>
static SQInteger Func1(HSQUIRRELVM vm) {
typedef void (*M)(A1);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value
);
return 0;
}
// Arg Count 2
template <class A1, class A2, SQInteger startIdx>
static SQInteger Func2(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value
);
return 0;
}
// Arg Count 3
template <class A1, class A2, class A3, SQInteger startIdx>
static SQInteger Func3(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value
);
return 0;
}
// Arg Count 4
template <class A1, class A2, class A3, class A4, SQInteger startIdx>
static SQInteger Func4(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value
);
return 0;
}
// Arg Count 5
template <class A1, class A2, class A3, class A4, class A5, SQInteger startIdx>
static SQInteger Func5(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value
);
return 0;
}
// Arg Count 6
template <class A1, class A2, class A3, class A4, class A5, class A6, SQInteger startIdx>
static SQInteger Func6(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value
);
return 0;
}
// Arg Count 7
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, SQInteger startIdx>
static SQInteger Func7(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value
);
return 0;
}
// Arg Count 8
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, SQInteger startIdx>
static SQInteger Func8(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value
);
return 0;
}
// Arg Count 9
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, SQInteger startIdx>
static SQInteger Func9(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value
);
return 0;
}
// Arg Count 10
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, SQInteger startIdx>
static SQInteger Func10(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value
);
return 0;
}
// Arg Count 11
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, SQInteger startIdx>
static SQInteger Func11(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value
);
return 0;
}
// Arg Count 12
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, SQInteger startIdx>
static SQInteger Func12(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value
);
return 0;
}
// Arg Count 13
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, SQInteger startIdx>
static SQInteger Func13(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value,
Var<A13>(vm, startIdx + 12).value
);
return 0;
}
// Arg Count 14
template <class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14, SQInteger startIdx>
static SQInteger Func14(HSQUIRRELVM vm) {
typedef void (*M)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14);
M* method;
sq_getuserdata(vm, -1, (SQUserPointer*)&method, NULL);
(*method)(
Var<A1>(vm, startIdx).value,
Var<A2>(vm, startIdx + 1).value,
Var<A3>(vm, startIdx + 2).value,
Var<A4>(vm, startIdx + 3).value,
Var<A5>(vm, startIdx + 4).value,
Var<A6>(vm, startIdx + 5).value,
Var<A7>(vm, startIdx + 6).value,
Var<A8>(vm, startIdx + 7).value,
Var<A9>(vm, startIdx + 8).value,
Var<A10>(vm, startIdx + 9).value,
Var<A11>(vm, startIdx + 10).value,
Var<A12>(vm, startIdx + 11).value,
Var<A13>(vm, startIdx + 12).value,
Var<A14>(vm, startIdx + 13).value
);
return 0;
}
};
//
// Global Function Resolvers
//
// Arg Count 0
template <class R>
SQFUNCTION SqGlobalFunc(R (*method)()) {
return &SqGlobal<R>::Func0;
}
// Arg Count 1
template <class R, class A1>
SQFUNCTION SqGlobalFunc(R (*method)(A1)) {
return &SqGlobal<R>::template Func1<A1, 2>;
}
// Arg Count 2
template <class R, class A1, class A2>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2)) {
return &SqGlobal<R>::template Func2<A1, A2, 2>;
}
// Arg Count 3
template <class R, class A1, class A2, class A3>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3)) {
return &SqGlobal<R>::template Func3<A1, A2, A3, 2>;
}
// Arg Count 4
template <class R, class A1, class A2, class A3, class A4>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4)) {
return &SqGlobal<R>::template Func4<A1, A2, A3, A4, 2>;
}
// Arg Count 5
template <class R, class A1, class A2, class A3, class A4, class A5>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5)) {
return &SqGlobal<R>::template Func5<A1, A2, A3, A4, A5, 2>;
}
// Arg Count 6
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6)) {
return &SqGlobal<R>::template Func6<A1, A2, A3, A4, A5, A6, 2>;
}
// Arg Count 7
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7)) {
return &SqGlobal<R>::template Func7<A1, A2, A3, A4, A5, A6, A7, 2>;
}
// Arg Count 8
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8)) {
return &SqGlobal<R>::template Func8<A1, A2, A3, A4, A5, A6, A7, A8, 2>;
}
// Arg Count 9
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) {
return &SqGlobal<R>::template Func9<A1, A2, A3, A4, A5, A6, A7, A8, A9, 2>;
}
// Arg Count 10
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) {
return &SqGlobal<R>::template Func10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, 2>;
}
// Arg Count 11
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)) {
return &SqGlobal<R>::template Func11<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, 2>;
}
// Arg Count 12
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)) {
return &SqGlobal<R>::template Func12<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, 2>;
}
// Arg Count 13
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)) {
return &SqGlobal<R>::template Func13<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, 2>;
}
// Arg Count 14
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
SQFUNCTION SqGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)) {
return &SqGlobal<R>::template Func14<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, 2>;
}
//
// Member Global Function Resolvers
//
// Arg Count 1
template <class R, class A1>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1)) {
return &SqGlobal<R>::template Func1<A1, 1>;
}
// Arg Count 2
template <class R, class A1, class A2>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2)) {
return &SqGlobal<R>::template Func2<A1, A2, 1>;
}
// Arg Count 3
template <class R, class A1, class A2, class A3>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3)) {
return &SqGlobal<R>::template Func3<A1, A2, A3, 1>;
}
// Arg Count 4
template <class R, class A1, class A2, class A3, class A4>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4)) {
return &SqGlobal<R>::template Func4<A1, A2, A3, A4, 1>;
}
// Arg Count 5
template <class R, class A1, class A2, class A3, class A4, class A5>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5)) {
return &SqGlobal<R>::template Func5<A1, A2, A3, A4, A5, 1>;
}
// Arg Count 6
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6)) {
return &SqGlobal<R>::template Func6<A1, A2, A3, A4, A5, A6, 1>;
}
// Arg Count 7
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7)) {
return &SqGlobal<R>::template Func7<A1, A2, A3, A4, A5, A6, A7, 1>;
}
// Arg Count 8
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8)) {
return &SqGlobal<R>::template Func8<A1, A2, A3, A4, A5, A6, A7, A8, 1>;
}
// Arg Count 9
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) {
return &SqGlobal<R>::template Func9<A1, A2, A3, A4, A5, A6, A7, A8, A9, 1>;
}
// Arg Count 10
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) {
return &SqGlobal<R>::template Func10<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, 1>;
}
// Arg Count 11
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)) {
return &SqGlobal<R>::template Func11<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, 1>;
}
// Arg Count 12
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)) {
return &SqGlobal<R>::template Func12<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, 1>;
}
// Arg Count 13
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)) {
return &SqGlobal<R>::template Func13<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, 1>;
}
// Arg Count 14
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
SQFUNCTION SqMemberGlobalFunc(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)) {
return &SqGlobal<R>::template Func14<A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, 1>;
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,310 +0,0 @@
//
// SqratObject: Referenced Squirrel Object Wrapper
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_OBJECT_H_)
#define _SCRAT_OBJECT_H_
#include <squirrel.h>
#include <string.h>
#include "sqratTypes.h"
#include "sqratOverloadMethods.h"
#include "sqratUtil.h"
namespace Sqrat {
class Object {
protected:
HSQUIRRELVM vm;
HSQOBJECT obj;
bool release;
Object(HSQUIRRELVM v, bool releaseOnDestroy = true) : vm(v), release(releaseOnDestroy) {
sq_resetobject(&obj);
}
public:
Object() : vm(0), release(true) {
sq_resetobject(&obj);
}
Object(const Object& so) : vm(so.vm), obj(so.obj), release(so.release) {
sq_addref(vm, &obj);
}
Object(HSQOBJECT o, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), obj(o), release(true) {
sq_addref(vm, &obj);
}
template<class T>
Object(T* instance, HSQUIRRELVM v = DefaultVM::Get()) : vm(v), release(true) {
ClassType<T>::PushInstance(vm, instance);
sq_getstackobj(vm, -1, &obj);
sq_addref(vm, &obj);
}
virtual ~Object() {
if(release) {
Release();
}
}
Object& operator=(const Object& so) {
if(release) {
Release();
}
vm = so.vm;
obj = so.obj;
release = so.release;
sq_addref(vm, &GetObject());
return *this;
}
HSQUIRRELVM& GetVM() {
return vm;
}
HSQUIRRELVM GetVM() const {
return vm;
}
SQObjectType GetType() const {
return GetObject()._type;
}
bool IsNull() const {
return sq_isnull(GetObject());
}
virtual HSQOBJECT GetObject() const {
return obj;
}
virtual HSQOBJECT& GetObject() {
return obj;
}
operator HSQOBJECT&() {
return GetObject();
}
void Release() {
sq_release(vm, &obj);
}
SQUserPointer GetInstanceUP(SQUserPointer tag = NULL) const {
SQUserPointer up;
sq_pushobject(vm, GetObject());
sq_getinstanceup(vm, -1, &up, tag);
sq_pop(vm, 1);
return up;
}
Object GetSlot(const SQChar* slot) const {
HSQOBJECT slotObj;
sq_pushobject(vm, GetObject());
sq_pushstring(vm, slot, -1);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return Object(vm); // Return a NULL object
} else {
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
}
template <class T>
T Cast() const {
sq_pushobject(vm, GetObject());
T ret = Var<T>(vm, -1).value;
sq_pop(vm, 1);
return ret;
}
Object GetSlot(SQInteger index) const {
HSQOBJECT slotObj;
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pop(vm, 1);
return Object(vm); // Return a NULL object
} else {
sq_getstackobj(vm, -1, &slotObj);
Object ret(slotObj, vm); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
}
template <class T>
inline Object operator[](T slot)
{
return GetSlot(slot);
}
SQInteger GetSize() const {
sq_pushobject(vm, GetObject());
SQInteger ret = sq_getsize(vm, -1);
sq_pop(vm, 1);
return ret;
}
protected:
// Bind a function and it's associated Squirrel closure to the object
inline void BindFunc(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
inline void BindFunc(const SQInteger index, void* method, size_t methodSize, SQFUNCTION func, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Bind a function and it's associated Squirrel closure to the object
inline void BindOverload(const SQChar* name, void* method, size_t methodSize, SQFUNCTION func, SQFUNCTION overload, int argCount, bool staticVar = false) {
string overloadName = SqOverloadName::Get(name, argCount);
sq_pushobject(vm, GetObject());
// Bind overload handler
sq_pushstring(vm, name, -1);
sq_pushstring(vm, name, -1); // function name is passed as a free variable
sq_newclosure(vm, overload, 1);
sq_newslot(vm, -3, staticVar);
// Bind overloaded function
sq_pushstring(vm, overloadName.c_str(), -1);
SQUserPointer methodPtr = sq_newuserdata(vm, static_cast<SQUnsignedInteger>(methodSize));
memcpy(methodPtr, method, methodSize);
sq_newclosure(vm, func, 1);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Set the value of a variable on the object. Changes to values set this way are not reciprocated
template<class V>
inline void BindValue(const SQChar* name, const V& val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
template<class V>
inline void BindValue(const SQInteger index, const V& val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
// Set the value of an instance on the object. Changes to values set this way are reciprocated back to the source instance
template<class V>
inline void BindInstance(const SQChar* name, V* val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
template<class V>
inline void BindInstance(const SQInteger index, V* val, bool staticVar = false) {
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
PushVar(vm, val);
sq_newslot(vm, -3, staticVar);
sq_pop(vm,1); // pop table
}
};
//
// Overridden Getter/Setter
//
template<>
struct Var<Object> {
Object value;
Var(HSQUIRRELVM vm, SQInteger idx) {
HSQOBJECT sqValue;
sq_getstackobj(vm, idx, &sqValue);
value = Object(sqValue, vm);
}
static void push(HSQUIRRELVM vm, Object& value) {
sq_pushobject(vm, value.GetObject());
}
};
template<>
struct Var<Object&> {
Object value;
Var(HSQUIRRELVM vm, SQInteger idx) {
HSQOBJECT sqValue;
sq_getstackobj(vm, idx, &sqValue);
value = Object(sqValue, vm);
}
static void push(HSQUIRRELVM vm, Object& value) {
sq_pushobject(vm, value.GetObject());
}
};
template<>
struct Var<const Object&> {
Object value;
Var(HSQUIRRELVM vm, SQInteger idx) {
HSQOBJECT sqValue;
sq_getstackobj(vm, idx, &sqValue);
value = Object(sqValue, vm);
}
static void push(HSQUIRRELVM vm, Object& value) {
sq_pushobject(vm, value.GetObject());
}
};
}
#endif

View File

@@ -1,485 +0,0 @@
//
// SqratGlobalMethods: Global Methods
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SQRAT_OVERLOAD_METHODS_H_)
#define _SQRAT_OVERLOAD_METHODS_H_
#include <squirrel.h>
#include <sqstdaux.h>
#include <sstream>
#include "sqratTypes.h"
#include "sqratUtil.h"
namespace Sqrat {
//
// Overload name generator
//
class SqOverloadName {
public:
static string Get(const SQChar* name, int args) {
std::basic_stringstream<SQChar> overloadName;
overloadName << _SC("__sqrat_ol_ ") << name << _SC("_") << args;
return overloadName.str();
}
};
//
// Squirrel Overload Functions
//
template <class R>
class SqOverload {
public:
static SQInteger Func(HSQUIRRELVM vm) {
// Get the arg count
int argCount = sq_gettop(vm) - 2;
const SQChar* funcName;
sq_getstring(vm, -1, &funcName); // get the function name (free variable)
string overloadName = SqOverloadName::Get(funcName, argCount);
sq_pushstring(vm, overloadName.c_str(), -1);
if(SQ_FAILED(sq_get(vm, 1))) { // Lookup the proper overload
return sq_throwerror(vm, "No overload matching this argument list found");// How to best appropriately error?
}
// Push the args again
for(int i = 1; i <= argCount + 1; ++i) {
sq_push(vm, i);
}
sq_call(vm, argCount + 1, true, ErrorHandling::IsEnabled());
return 1;
}
};
//
// void return specialization
//
template <>
class SqOverload<void> {
public:
static SQInteger Func(HSQUIRRELVM vm) {
// Get the arg count
int argCount = sq_gettop(vm) - 2;
const SQChar* funcName;
sq_getstring(vm, -1, &funcName); // get the function name (free variable)
string overloadName = SqOverloadName::Get(funcName, argCount);
sq_pushstring(vm, overloadName.c_str(), -1);
if(SQ_FAILED(sq_get(vm, 1))) { // Lookup the proper overload
return sq_throwerror(vm, "No overload matching this argument list found");// How to best appropriately error?
}
// Push the args again
for(int i = 1; i <= argCount + 1; ++i) {
sq_push(vm, i);
}
sq_call(vm, argCount + 1, false, ErrorHandling::IsEnabled());
return 0;
}
};
//
// Overload handler resolver
//
template <class R>
inline SQFUNCTION SqOverloadFunc(R (*method)) {
return &SqOverload<R>::Func;
}
template <class C, class R>
inline SQFUNCTION SqOverloadFunc(R (C::*method)) {
return &SqOverload<R>::Func;
}
template <class C, class R>
inline SQFUNCTION SqOverloadFunc(R (C::*method)() const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) const ) {
return &SqOverload<R>::Func;
}
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
inline SQFUNCTION SqOverloadFunc(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) const ) {
return &SqOverload<R>::Func;
}
//
// Query argument count
//
// Arg Count 0
template <class R>
inline int SqGetArgCount(R (*method)()) {
return 0;
}
// Arg Count 1
template <class R, class A1>
inline int SqGetArgCount(R (*method)(A1)) {
return 1;
}
// Arg Count 2
template <class R, class A1, class A2>
inline int SqGetArgCount(R (*method)(A1, A2)) {
return 2;
}
// Arg Count 3
template <class R, class A1, class A2, class A3>
inline int SqGetArgCount(R (*method)(A1, A2, A3)) {
return 3;
}
// Arg Count 4
template <class R, class A1, class A2, class A3, class A4>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4)) {
return 4;
}
// Arg Count 5
template <class R, class A1, class A2, class A3, class A4, class A5>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5)) {
return 5;
}
// Arg Count 6
template <class R, class A1, class A2, class A3, class A4, class A5, class A6>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6)) {
return 6;
}
// Arg Count 7
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7)) {
return 7;
}
// Arg Count 8
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8)) {
return 8;
}
// Arg Count 9
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) {
return 9;
}
// Arg Count 10
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) {
return 10;
}
// Arg Count 11
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)) {
return 11;
}
// Arg Count 12
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)) {
return 12;
}
// Arg Count 13
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)) {
return 13;
}
// Arg Count 14
template <class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
inline int SqGetArgCount(R (*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)) {
return 14;
}
//
// Query member function argument count
//
// Arg Count 0
template <class C, class R>
inline int SqGetArgCount(R (C::*method)()) {
return 0;
}
// Arg Count 1
template <class C, class R, class A1>
inline int SqGetArgCount(R (C::*method)(A1)) {
return 1;
}
// Arg Count 2
template <class C, class R, class A1, class A2>
inline int SqGetArgCount(R (C::*method)(A1, A2)) {
return 2;
}
// Arg Count 3
template <class C, class R, class A1, class A2, class A3>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3)) {
return 3;
}
// Arg Count 4
template <class C, class R, class A1, class A2, class A3, class A4>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4)) {
return 4;
}
// Arg Count 5
template <class C, class R, class A1, class A2, class A3, class A4, class A5>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5)) {
return 5;
}
// Arg Count 6
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6)) {
return 6;
}
// Arg Count 7
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7)) {
return 7;
}
// Arg Count 8
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8)) {
return 8;
}
// Arg Count 9
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9)) {
return 9;
}
// Arg Count 10
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10)) {
return 10;
}
// Arg Count 11
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)) {
return 11;
}
// Arg Count 12
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12)) {
return 12;
}
// Arg Count 13
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13)) {
return 13;
}
// Arg Count 14
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14)) {
return 14;
}
//
// Query const member function argument count
//
// Arg Count 0
template <class C, class R>
inline int SqGetArgCount(R (C::*method)() const) {
return 0;
}
// Arg Count 1
template <class C, class R, class A1>
inline int SqGetArgCount(R (C::*method)(A1) const) {
return 1;
}
// Arg Count 2
template <class C, class R, class A1, class A2>
inline int SqGetArgCount(R (C::*method)(A1, A2) const) {
return 2;
}
// Arg Count 3
template <class C, class R, class A1, class A2, class A3>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3) const) {
return 3;
}
// Arg Count 4
template <class C, class R, class A1, class A2, class A3, class A4>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4) const) {
return 4;
}
// Arg Count 5
template <class C, class R, class A1, class A2, class A3, class A4, class A5>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5) const) {
return 5;
}
// Arg Count 6
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6) const) {
return 6;
}
// Arg Count 7
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7) const) {
return 7;
}
// Arg Count 8
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8) const) {
return 8;
}
// Arg Count 9
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const) {
return 9;
}
// Arg Count 10
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const) {
return 10;
}
// Arg Count 11
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) const) {
return 11;
}
// Arg Count 12
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) const) {
return 12;
}
// Arg Count 13
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) const) {
return 13;
}
// Arg Count 14
template <class C, class R, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14>
inline int SqGetArgCount(R (C::*method)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) const) {
return 14;
}
}
#endif

View File

@@ -1,141 +0,0 @@
//
// SqratScript: Script Compilation and Execution
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_SCRIPT_H_)
#define _SCRAT_SCRIPT_H_
#include <squirrel.h>
#include <sqstdio.h>
#include <string.h>
#include "sqratObject.h"
namespace Sqrat {
class Script : public Object {
public:
Script(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, false) {
}
~Script()
{
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
}
}
void CompileString(const string& script) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
}
if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() * sizeof(SQChar)), _SC(""), true))) {
throw Exception(LastErrorString(vm));
}
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
}
bool CompileString(const string& script, string& errMsg) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
}
if(SQ_FAILED(sq_compilebuffer(vm, script.c_str(), static_cast<SQInteger>(script.size() * sizeof(SQChar)), _SC(""), true))) {
errMsg = LastErrorString(vm);
return false;
}
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
return true;
}
void CompileFile(const string& path) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
}
if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) {
throw Exception(LastErrorString(vm));
}
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
}
bool CompileFile(const string& path, string& errMsg) {
if(!sq_isnull(obj)) {
sq_release(vm, &obj);
}
if(SQ_FAILED(sqstd_loadfile(vm, path.c_str(), true))) {
errMsg = LastErrorString(vm);
return false;
}
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm, 1);
return true;
}
void Run() {
if(!sq_isnull(obj)) {
SQRESULT result;
sq_pushobject(vm, obj);
sq_pushroottable(vm);
result = sq_call(vm, 1, false, true);
sq_pop(vm, 1);
if(SQ_FAILED(result)) {
throw Exception(LastErrorString(vm));
}
}
}
bool Run(string& errMsg) {
if(!sq_isnull(obj)) {
SQRESULT result;
sq_pushobject(vm, obj);
sq_pushroottable(vm);
result = sq_call(vm, 1, false, true);
sq_pop(vm, 1);
if(SQ_FAILED(result)) {
errMsg = LastErrorString(vm);
return false;
}
}
return true;
}
void WriteCompiledFile(const string& path) {
if(!sq_isnull(obj)) {
sq_pushobject(vm, obj);
sqstd_writeclosuretofile(vm, path.c_str());
//sq_pop(vm, 1); // needed?
}
}
};
}
#endif

View File

@@ -1,162 +0,0 @@
//
// SqratTable: Table Binding
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_TABLE_H_)
#define _SCRAT_TABLE_H_
#include <squirrel.h>
#include <string.h>
#include "sqratObject.h"
#include "sqratFunction.h"
#include "sqratGlobalMethods.h"
namespace Sqrat {
class TableBase : public Object {
public:
TableBase(HSQUIRRELVM v = DefaultVM::Get()) : Object(v, true) {
}
TableBase(const Object& obj) : Object(obj) {
}
// Bind a Table or Class to the Table (Can be used to facilitate Namespaces)
// Note: Bind cannot be called "inline" like other functions because it introduces order-of-initialization bugs.
void Bind(const SQChar* name, Object& obj) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
sq_pushobject(vm, obj.GetObject());
sq_newslot(vm, -3, false);
sq_pop(vm,1); // pop table
}
// Bind a raw Squirrel closure to the Table
TableBase& SquirrelFunc(const SQChar* name, SQFUNCTION func) {
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
sq_newclosure(vm, func, 0);
sq_newslot(vm, -3, false);
sq_pop(vm,1); // pop table
return *this;
}
//
// Variable Binding
//
template<class V>
TableBase& SetValue(const SQChar* name, const V& val) {
BindValue<V>(name, val, false);
return *this;
}
template<class V>
TableBase& SetValue(const SQInteger index, const V& val) {
BindValue<V>(index, val, false);
return *this;
}
template<class V>
TableBase& SetInstance(const SQChar* name, V* val) {
BindInstance<V>(name, val, false);
return *this;
}
template<class F>
TableBase& Func(const SQChar* name, F method) {
BindFunc(name, &method, sizeof(method), SqGlobalFunc(method));
return *this;
}
template<class F>
TableBase& Overload(const SQChar* name, F method) {
BindOverload(name, &method, sizeof(method), SqGlobalFunc(method), SqOverloadFunc(method), SqGetArgCount(method));
return *this;
}
//
// Function Calls
//
Function GetFunction(const SQChar* name) {
HSQOBJECT funcObj;
sq_pushobject(vm, GetObject());
sq_pushstring(vm, name, -1);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pushnull(vm);
}
sq_getstackobj(vm, -1, &funcObj);
Function ret(vm, GetObject(), funcObj); // must addref before the pop!
sq_pop(vm, 2);
return ret;
}
Function GetFunction(const SQInteger index) {
HSQOBJECT funcObj;
sq_pushobject(vm, GetObject());
sq_pushinteger(vm, index);
if(SQ_FAILED(sq_get(vm, -2))) {
sq_pushnull(vm);
}
sq_getstackobj(vm, -1, &funcObj);
Function ret(vm, GetObject(), funcObj);
sq_pop(vm, 2);
return ret;
}
};
class Table : public TableBase {
public:
Table(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
sq_newtable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(vm,1);
}
Table(const Object& obj) : TableBase(obj) {
}
};
//
// Root Table
//
class RootTable : public TableBase {
public:
RootTable(HSQUIRRELVM v = DefaultVM::Get()) : TableBase(v) {
sq_pushroottable(vm);
sq_getstackobj(vm,-1,&obj);
sq_addref(vm, &obj);
sq_pop(v,1); // pop root table
}
};
}
#endif

View File

@@ -1,341 +0,0 @@
//
// SqratTypes: Type Translators
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.
//
#if !defined(_SCRAT_TYPES_H_)
#define _SCRAT_TYPES_H_
#include <squirrel.h>
#include <string>
#include "sqratClassType.h"
namespace Sqrat {
//
// Variable Accessors
//
// Generic classes
template<class T>
struct Var {
T value;
Var(HSQUIRRELVM vm, SQInteger idx) {
value = *ClassType<T>::GetInstance(vm, idx);
}
static void push(HSQUIRRELVM vm, T value) {
ClassType<T>::PushInstanceCopy(vm, value);
}
};
template<class T>
struct Var<T&> {
T value;
Var(HSQUIRRELVM vm, SQInteger idx) {
value = *ClassType<T>::GetInstance(vm, idx);
}
static void push(HSQUIRRELVM vm, T value) {
ClassType<T>::PushInstanceCopy(vm, value);
}
};
template<class T>
struct Var<T*> {
T* value;
Var(HSQUIRRELVM vm, SQInteger idx) {
value = ClassType<T>::GetInstance(vm, idx);
}
static void push(HSQUIRRELVM vm, T* value) {
ClassType<T>::PushInstance(vm, value);
}
};
template<class T>
struct Var<const T&> {
T value;
Var(HSQUIRRELVM vm, SQInteger idx) {
value = *ClassType<T>::GetInstance(vm, idx);
}
static void push(HSQUIRRELVM vm, T value) {
ClassType<T>::PushInstanceCopy(vm, value);
}
};
template<class T>
struct Var<const T*> {
T* value;
Var(HSQUIRRELVM vm, SQInteger idx) {
value = ClassType<T>::GetInstance(vm, idx);
}
static void push(HSQUIRRELVM vm, T* value) {
ClassType<T>::PushInstance(vm, value);
}
};
// Integer Types
#define SCRAT_INTEGER( type ) \
template<> \
struct Var<type> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQInteger sqValue; \
sq_getinteger(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, type& value) { \
sq_pushinteger(vm, static_cast<SQInteger>(value)); \
} \
};\
\
template<> \
struct Var<const type> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQInteger sqValue; \
sq_getinteger(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, const type& value) { \
sq_pushinteger(vm, static_cast<SQInteger>(value)); \
} \
}; \
\
template<> \
struct Var<const type&> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQInteger sqValue; \
sq_getinteger(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, const type& value) { \
sq_pushinteger(vm, static_cast<SQInteger>(value)); \
} \
};
SCRAT_INTEGER(unsigned int)
SCRAT_INTEGER(signed int)
SCRAT_INTEGER(unsigned long)
SCRAT_INTEGER(signed long)
SCRAT_INTEGER(unsigned short)
SCRAT_INTEGER(signed short)
#if defined(__int64)
SCRAT_INTEGER(unsigned __int64)
SCRAT_INTEGER(signed __int64)
#endif
// Float Types
#define SCRAT_FLOAT( type ) \
template<> \
struct Var<type> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQFloat sqValue; \
sq_getfloat(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, type& value) { \
sq_pushfloat(vm, static_cast<SQFloat>(value)); \
} \
}; \
\
template<> \
struct Var<const type> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQFloat sqValue; \
sq_getfloat(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, const type& value) { \
sq_pushfloat(vm, static_cast<SQFloat>(value)); \
} \
}; \
template<> \
struct Var<const type&> { \
type value; \
Var(HSQUIRRELVM vm, SQInteger idx) { \
SQFloat sqValue; \
sq_getfloat(vm, idx, &sqValue); \
value = static_cast<type>(sqValue); \
} \
static void push(HSQUIRRELVM vm, const type& value) { \
sq_pushfloat(vm, static_cast<SQFloat>(value)); \
} \
};
SCRAT_FLOAT(float)
SCRAT_FLOAT(double)
// Boolean Types
template<>
struct Var<bool> {
bool value;
Var(HSQUIRRELVM vm, SQInteger idx) {
SQBool sqValue;
sq_tobool(vm, idx, &sqValue);
value = (sqValue != 0);
}
static void push(HSQUIRRELVM vm, bool& value) {
sq_pushbool(vm, static_cast<SQBool>(value));
}
};
template<>
struct Var<const bool> {
bool value;
Var(HSQUIRRELVM vm, SQInteger idx) {
SQBool sqValue;
sq_tobool(vm, idx, &sqValue);
value = (sqValue != 0);
}
static void push(HSQUIRRELVM vm, const bool& value) {
sq_pushbool(vm, static_cast<SQBool>(value));
}
};
template<>
struct Var<const bool&> {
bool value;
Var(HSQUIRRELVM vm, SQInteger idx) {
SQBool sqValue;
sq_tobool(vm, idx, &sqValue);
value = (sqValue != 0);
}
static void push(HSQUIRRELVM vm, const bool& value) {
sq_pushbool(vm, static_cast<SQBool>(value));
}
};
// String Types
typedef std::basic_string<SQChar> string;
template<>
struct Var<SQChar*> {
SQChar* value;
HSQOBJECT obj;/* hold a reference to the object holding value during the Var struct lifetime*/
HSQUIRRELVM v;
Var(HSQUIRRELVM vm, SQInteger idx) {
sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, (const SQChar**)&value);
sq_addref(vm, &obj);
sq_pop(vm,1);
v = vm;
}
~Var()
{
if(v && !sq_isnull(obj)) {
sq_release(v, &obj);
}
}
static void push(HSQUIRRELVM vm, SQChar* value) {
sq_pushstring(vm, value, -1);
}
};
template<>
struct Var<const SQChar*> {
const SQChar* value;
HSQOBJECT obj; /* hold a reference to the object holding value during the Var struct lifetime*/
HSQUIRRELVM v;
Var(HSQUIRRELVM vm, SQInteger idx) {
sq_tostring(vm, idx);
sq_getstackobj(vm, -1, &obj);
sq_getstring(vm, -1, &value);
sq_addref(vm, &obj);
sq_pop(vm,1);
v = vm;
}
~Var()
{
if(v && !sq_isnull(obj)) {
sq_release(v, &obj);
}
}
static void push(HSQUIRRELVM vm, const SQChar* value) {
sq_pushstring(vm, value, -1);
}
};
template<>
struct Var<string> {
string value;
Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret;
sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret);
value = string(ret);
sq_pop(vm,1);
}
static void push(HSQUIRRELVM vm, string value) {
sq_pushstring(vm, value.c_str(), -1);
}
};
template<>
struct Var<string&> {
string value;
Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret;
sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret);
value = string(ret);
sq_pop(vm,1);
}
static void push(HSQUIRRELVM vm, string value) {
sq_pushstring(vm, value.c_str(), -1);
}
};
template<>
struct Var<const string&> {
string value;
Var(HSQUIRRELVM vm, SQInteger idx) {
const SQChar* ret;
sq_tostring(vm, idx);
sq_getstring(vm, -1, &ret);
value = string(ret);
sq_pop(vm,1);
}
static void push(HSQUIRRELVM vm, string value) {
sq_pushstring(vm, value.c_str(), -1);
}
};
//
// Variable Accessors
//
// Push
template<class T>
inline void PushVar(HSQUIRRELVM vm, T value) {
Var<T>::push(vm, value);
}
}
#endif

View File

@@ -1,94 +0,0 @@
//
// SqratUtil: Squirrel Utilities
//
//
// Copyright (c) 2009 Brandon Jones
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source
// distribution.