Squirrel Plugins
I worked a little bit on the squirrel Bindings They work now on linux and windows :) (OSX is untested, but should work also) but they are very limited at the moment. (Only made OnChat working) I also fixed some small bugs. git-svn-id: http://mc-server.googlecode.com/svn/trunk@648 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
358e74ded8
commit
083228a10d
@ -52,7 +52,10 @@ INCLUDE = -I.\
|
||||
-IiniFile\
|
||||
-Itolua++-1.0.93/include\
|
||||
-Ijsoncpp-src-0.5.0/include\
|
||||
-Ijsoncpp-src-0.5.0/src/lib_json
|
||||
-Ijsoncpp-src-0.5.0/src/lib_json\
|
||||
-Isquirrel_3_0_1_stable/include\
|
||||
-Isquirrel_3_0_1_stable\
|
||||
-Isquirrel_3_0_1_stable/sqrat
|
||||
|
||||
#
|
||||
# Build MCServer
|
||||
|
@ -1,26 +1,20 @@
|
||||
class SquirrelChatLog extends cPlugin__Squirrel
|
||||
class SquirrelChatLog extends Plugin
|
||||
{
|
||||
constructor()
|
||||
{
|
||||
base.constructor();
|
||||
}
|
||||
|
||||
name = "SquirrelChatLogger";
|
||||
|
||||
function Initialize()
|
||||
{
|
||||
::print("SquirrelChatLog initialize()");
|
||||
this.SetName("SquirrelChatLog");
|
||||
|
||||
local PluginManager = cRoot.Get().GetPluginManager();
|
||||
PluginManager.AddHook( this, PluginManager.E_PLUGIN_CHAT );
|
||||
this.AddHook(Hook.Chat);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function OnChat( Message, Player )
|
||||
{
|
||||
::print("CHAT");
|
||||
::print(Player.GetName() + ": " + Message);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Plugin <- SquirrelChatLog();
|
||||
cRoot.Get().GetPluginManager().AddPlugin( Plugin );
|
||||
|
@ -99,7 +99,7 @@
|
||||
<ClCompile>
|
||||
<AdditionalOptions>/ZI /D_DEBUG %(AdditionalOptions)</AdditionalOptions>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;..\squirrel_3_0_1_stable\sqrat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
@ -130,7 +130,7 @@
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug with optimized Noise|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;..\squirrel_3_0_1_stable\sqrat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<ExceptionHandling>Sync</ExceptionHandling>
|
||||
@ -228,7 +228,7 @@
|
||||
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>..\tolua++-1.0.93\include;..\lua-5.1.4\src;..\zlib-1.2.7;..\mysql-connector\include;..\source\;..\pdcurs34\;..\jsoncpp-src-0.5.0\include;..\squirrel_3_0_1_stable\include;..\squirrel_3_0_1_stable;..\squirrel_3_0_1_stable\sqrat;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||
@ -306,6 +306,7 @@
|
||||
<ClCompile Include="..\source\BlockID.cpp" />
|
||||
<ClCompile Include="..\source\cAggressiveMonster.cpp" />
|
||||
<ClCompile Include="..\Source\cAuthenticator.cpp" />
|
||||
<ClCompile Include="..\source\cBlockArea.cpp" />
|
||||
<ClCompile Include="..\source\cBlockingTCPLink.cpp" />
|
||||
<ClCompile Include="..\source\cCavespider.cpp" />
|
||||
<ClCompile Include="..\Source\cChicken.cpp" />
|
||||
@ -356,6 +357,7 @@
|
||||
<ClCompile Include="..\source\cPiston.cpp" />
|
||||
<ClCompile Include="..\Source\cPluginManager.cpp" />
|
||||
<ClCompile Include="..\source\cPlugin_NewLua.cpp" />
|
||||
<ClCompile Include="..\source\cPlugin_Squirrel.cpp" />
|
||||
<ClCompile Include="..\source\CraftingRecipes.cpp" />
|
||||
<ClCompile Include="..\source\cRedstone.cpp" />
|
||||
<ClCompile Include="..\source\cRedstoneSimulator.cpp" />
|
||||
@ -472,7 +474,8 @@
|
||||
<ClCompile Include="..\source\packets\cPacket_WindowClick.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_WindowClose.cpp" />
|
||||
<ClCompile Include="..\source\packets\cPacket_WindowOpen.cpp" />
|
||||
<ClCompile Include="..\source\SquirrelBindings.cpp" />
|
||||
<ClCompile Include="..\source\squirrelbindings\SquirrelBindings.cpp" />
|
||||
<ClCompile Include="..\source\squirrelbindings\SquirrelFunctions.cpp" />
|
||||
<ClCompile Include="..\source\StackWalker.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug with optimized Noise|Win32'">NotUsing</PrecompiledHeader>
|
||||
@ -495,6 +498,7 @@
|
||||
<ClInclude Include="..\Source\BlockID.h" />
|
||||
<ClInclude Include="..\source\cAggressiveMonster.h" />
|
||||
<ClInclude Include="..\Source\cAuthenticator.h" />
|
||||
<ClInclude Include="..\source\cBlockArea.h" />
|
||||
<ClInclude Include="..\source\cBlockingTCPLink.h" />
|
||||
<ClInclude Include="..\source\cCavespider.h" />
|
||||
<ClInclude Include="..\Source\cChicken.h" />
|
||||
@ -522,6 +526,7 @@
|
||||
<ClInclude Include="..\source\ChunkSender.h" />
|
||||
<ClInclude Include="..\source\cIsThread.h" />
|
||||
<ClInclude Include="..\Source\cLadder.h" />
|
||||
<ClInclude Include="..\source\cPlugin_Squirrel.h" />
|
||||
<ClInclude Include="..\Source\cVine.h" />
|
||||
<ClInclude Include="..\source\cLavaSimulator.h" />
|
||||
<ClInclude Include="..\Source\cLuaCommandBinder.h" />
|
||||
@ -660,7 +665,10 @@
|
||||
<ClInclude Include="..\source\packets\cPacket_WindowClick.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_WindowClose.h" />
|
||||
<ClInclude Include="..\source\packets\cPacket_WindowOpen.h" />
|
||||
<ClInclude Include="..\source\SquirrelBindings.h" />
|
||||
<ClInclude Include="..\source\squirrelbindings\cSquirrelBaseClass.h" />
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelBindings.h" />
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelFunctions.h" />
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelObject.h" />
|
||||
<ClInclude Include="..\source\StackWalker.h" />
|
||||
<ClInclude Include="..\source\StringCompression.h" />
|
||||
<ClInclude Include="..\source\StringUtils.h" />
|
||||
@ -706,4 +714,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -427,12 +427,15 @@
|
||||
<Filter Include="Simulator\cSimulator\cRedstoneSimulator">
|
||||
<UniqueIdentifier>{4b3b7b43-8e8b-4823-b112-2259fdfff7d3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Generating">
|
||||
<UniqueIdentifier>{833e49bd-848d-42de-ac60-6cd7656474e3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Storage">
|
||||
<UniqueIdentifier>{038cf4bd-108e-44e2-bdcb-9d48fb26676e}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="cPlugin\cPlugin_Squirrel">
|
||||
<UniqueIdentifier>{43f91962-ebda-4195-aadc-921eca3c8356}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="HandyStuff\Generating">
|
||||
<UniqueIdentifier>{833e49bd-848d-42de-ac60-6cd7656474e3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\source\cServer.cpp">
|
||||
@ -799,9 +802,6 @@
|
||||
<ClCompile Include="..\source\cLavaSimulator.cpp">
|
||||
<Filter>Simulator\cSimulator\cFluidSimulator\cLavaSimulator</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\SquirrelBindings.cpp">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\packets\cPacket_Explosion.cpp">
|
||||
<Filter>Packets\cPacket_Explosion</Filter>
|
||||
</ClCompile>
|
||||
@ -870,26 +870,26 @@
|
||||
<Filter>Packets</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cChunkGenerator.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\Trees.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\CompoGen.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\HeiGen.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\StructGen.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\BioGen.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\BlockID.cpp" />
|
||||
<ClCompile Include="..\source\FinishGen.cpp">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\WorldStorage.cpp">
|
||||
<Filter>Storage</Filter>
|
||||
@ -904,6 +904,16 @@
|
||||
<Filter>Storage</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\CraftingRecipes.cpp" />
|
||||
<ClCompile Include="..\source\cBlockArea.cpp" />
|
||||
<ClCompile Include="..\source\squirrelbindings\SquirrelBindings.cpp">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\cPlugin_Squirrel.cpp">
|
||||
<Filter>cPlugin\cPlugin_Squirrel</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\source\squirrelbindings\SquirrelFunctions.cpp">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\source\cServer.h">
|
||||
@ -1308,9 +1318,6 @@
|
||||
<ClInclude Include="..\source\cLavaSimulator.h">
|
||||
<Filter>Simulator\cSimulator\cFluidSimulator\cLavaSimulator</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\SquirrelBindings.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\packets\cPacket_Explosion.h">
|
||||
<Filter>Packets\cPacket_Explosion</Filter>
|
||||
</ClInclude>
|
||||
@ -1380,25 +1387,25 @@
|
||||
<Filter>Packets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cChunkGenerator.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\StructGen.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\Trees.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\CompoGen.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\HeiGen.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\BioGen.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\FinishGen.h">
|
||||
<Filter>Generating</Filter>
|
||||
<Filter>HandyStuff\Generating</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\WorldStorage.h">
|
||||
<Filter>Storage</Filter>
|
||||
@ -1414,6 +1421,22 @@
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cStep.h" />
|
||||
<ClInclude Include="..\source\CraftingRecipes.h" />
|
||||
<ClInclude Include="..\source\cBlockArea.h" />
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelBindings.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\cPlugin_Squirrel.h">
|
||||
<Filter>cPlugin\cPlugin_Squirrel</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelFunctions.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\squirrelbindings\SquirrelObject.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\source\squirrelbindings\cSquirrelBaseClass.h">
|
||||
<Filter>LuaBindings\SquirrelBindings</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\source\AllToLua.pkg">
|
||||
@ -1430,4 +1453,4 @@
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="MCServer.rc" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -72,13 +72,6 @@
|
||||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlus.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOCharBuf.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlusUtf8.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtils.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtilsWin32.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelObject.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelVM.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdaux.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdblob.cpp" />
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdio.cpp" />
|
||||
@ -101,21 +94,6 @@
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\squirrel\sqvm.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\sqplus.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusCallTemplates.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusConst.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusFunctionCallImpl.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOCharBuf.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOverload.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusSetup.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusSmartPointer.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusTypeMask.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusUtf8.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\sqplusWin32.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtils.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtilsWin32.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelObject.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelVM.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdblobimpl.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdstream.h" />
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\squirrel\sqarray.h" />
|
||||
|
@ -7,9 +7,6 @@
|
||||
<Filter Include="sqstdlib">
|
||||
<UniqueIdentifier>{819d39f8-4859-48ad-b096-04f8d6811524}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="sqplus">
|
||||
<UniqueIdentifier>{d9a1c0d8-bd70-4686-9a3d-c35c9d3365e3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\squirrel\sqapi.cpp">
|
||||
@ -72,27 +69,6 @@
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdsystem.cpp">
|
||||
<Filter>sqstdlib</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlus.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOCharBuf.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SqPlusUtf8.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtils.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtilsWin32.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelObject.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\squirrel_3_0_1_stable\sqplus\SquirrelVM.cpp">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\squirrel\sqarray.h">
|
||||
@ -149,50 +125,5 @@
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqstdlib\sqstdstream.h">
|
||||
<Filter>sqstdlib</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\sqplus.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusCallTemplates.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusConst.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusFunctionCallImpl.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOCharBuf.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusOverload.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusSetup.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusSmartPointer.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusTypeMask.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SqPlusUtf8.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\sqplusWin32.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtils.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelBindingsUtilsWin32.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelObject.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\squirrel_3_0_1_stable\sqplus\SquirrelVM.h">
|
||||
<Filter>sqplus</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
138
makefile_base
138
makefile_base
@ -25,7 +25,10 @@ INCLUDE = -I.\
|
||||
-IiniFile\
|
||||
-Itolua++-1.0.93/include\
|
||||
-Ijsoncpp-src-0.5.0/include\
|
||||
-Ijsoncpp-src-0.5.0/src/lib_json
|
||||
-Ijsoncpp-src-0.5.0/src/lib_json\
|
||||
-Isquirrel_3_0_1_stable/include\
|
||||
-Isquirrel_3_0_1_stable\
|
||||
-Isquirrel_3_0_1_stable/sqrat
|
||||
|
||||
|
||||
#
|
||||
@ -66,6 +69,7 @@ MCServer : \
|
||||
build/cReferenceManager.o\
|
||||
build/Bindings.o\
|
||||
build/BlockID.o\
|
||||
build/cBlockArea.o\
|
||||
build/cBlockToPickup.o\
|
||||
build/cChatColor.o\
|
||||
build/cChestEntity.o\
|
||||
@ -115,10 +119,10 @@ MCServer : \
|
||||
build/cWebAdmin.o\
|
||||
build/cWebPlugin.o\
|
||||
build/cWindow.o\
|
||||
build/LightingThread.o\
|
||||
build/LightingThread.o\
|
||||
build/cRedstoneSimulator.o\
|
||||
build/ChunkSender.o\
|
||||
build/cWorld.o\
|
||||
build/cWorld.o\
|
||||
build/main.o\
|
||||
build/ManualBindings.o\
|
||||
build/Matrix4f.o\
|
||||
@ -253,7 +257,32 @@ MCServer : \
|
||||
build/WSSAnvil.o\
|
||||
build/FastNBT.o\
|
||||
build/StringCompression.o\
|
||||
build/StringCompression.o\
|
||||
build/sqstdaux.o\
|
||||
build/sqstdblob.o\
|
||||
build/sqstdio.o\
|
||||
build/sqstdmath.o\
|
||||
build/sqstdrex.o\
|
||||
build/sqstdstream.o\
|
||||
build/sqstdstring.o\
|
||||
build/sqstdsystem.o\
|
||||
build/sqapi.o\
|
||||
build/sqbaselib.o\
|
||||
build/sqclass.o\
|
||||
build/sqcompiler.o\
|
||||
build/sqdebug.o\
|
||||
build/sqfuncstate.o\
|
||||
build/sqlexer.o\
|
||||
build/sqmem.o\
|
||||
build/sqobject.o\
|
||||
build/sqstate.o\
|
||||
build/sqtable.o\
|
||||
build/sqvm.o\
|
||||
build/squirrelbindings/SquirrelBindings.o\
|
||||
build/squirrelbindings/SquirrelFunctions.o\
|
||||
build/cPlugin_Squirrel.o\
|
||||
build/CraftingRecipes.o
|
||||
|
||||
$(CC) $(LNK_OPTIONS) \
|
||||
build/json_reader.o\
|
||||
build/json_value.o\
|
||||
@ -288,6 +317,7 @@ MCServer : \
|
||||
build/cReferenceManager.o\
|
||||
build/Bindings.o\
|
||||
build/BlockID.o\
|
||||
build/cBlockArea.o\
|
||||
build/cBlockToPickup.o\
|
||||
build/cChatColor.o\
|
||||
build/cChestEntity.o\
|
||||
@ -476,6 +506,29 @@ MCServer : \
|
||||
build/FastNBT.o\
|
||||
build/StringCompression.o\
|
||||
build/CraftingRecipes.o\
|
||||
build/sqstdaux.o\
|
||||
build/sqstdblob.o\
|
||||
build/sqstdio.o\
|
||||
build/sqstdmath.o\
|
||||
build/sqstdrex.o\
|
||||
build/sqstdstream.o\
|
||||
build/sqstdstring.o\
|
||||
build/sqstdsystem.o\
|
||||
build/sqapi.o\
|
||||
build/sqbaselib.o\
|
||||
build/sqclass.o\
|
||||
build/sqcompiler.o\
|
||||
build/sqdebug.o\
|
||||
build/sqfuncstate.o\
|
||||
build/sqlexer.o\
|
||||
build/sqmem.o\
|
||||
build/sqobject.o\
|
||||
build/sqstate.o\
|
||||
build/sqtable.o\
|
||||
build/sqvm.o\
|
||||
build/squirrelbindings/SquirrelBindings.o\
|
||||
build/squirrelbindings/SquirrelFunctions.o\
|
||||
build/cPlugin_Squirrel.o\
|
||||
-o MCServer
|
||||
|
||||
clean :
|
||||
@ -696,6 +749,29 @@ clean :
|
||||
build/cIsThread.o\
|
||||
build/cSocketThreads.o\
|
||||
build/CraftingRecipes.o\
|
||||
build/sqstdaux.o\
|
||||
build/sqstdblob.o\
|
||||
build/sqstdio.o\
|
||||
build/sqstdmath.o\
|
||||
build/sqstdrex.o\
|
||||
build/sqstdstream.o\
|
||||
build/sqstdstring.o\
|
||||
build/sqstdsystem.o\
|
||||
build/sqapi.o\
|
||||
build/sqbaselib.o\
|
||||
build/sqclass.o\
|
||||
build/sqcompiler.o\
|
||||
build/sqdebug.o\
|
||||
build/sqfuncstate.o\
|
||||
build/sqlexer.o\
|
||||
build/sqmem.o\
|
||||
build/sqobject.o\
|
||||
build/sqstate.o\
|
||||
build/sqtable.o\
|
||||
build/sqvm.o\
|
||||
build/squirrelbindings/SquirrelBindings.o\
|
||||
build/squirrelbindings/SquirrelFunctions.o\
|
||||
build/cPlugin_Squirrel.o\
|
||||
MCServer
|
||||
|
||||
install : MCServer
|
||||
@ -734,6 +810,9 @@ build/Bindings.o : source/Bindings.cpp
|
||||
build/BlockID.o : source/BlockID.cpp
|
||||
$(CC) $(CC_OPTIONS) source/BlockID.cpp -c $(INCLUDE) -o build/BlockID.o
|
||||
|
||||
build/cBlockArea.o : source/cBlockArea.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cBlockArea.cpp -c $(INCLUDE) -o build/cBlockArea.o
|
||||
|
||||
|
||||
# Item # 6 -- cBlockToPickup --
|
||||
build/cBlockToPickup.o : source/cBlockToPickup.cpp
|
||||
@ -1602,7 +1681,58 @@ build/cRedstoneSimulator.o : source/cRedstoneSimulator.cpp
|
||||
build/CraftingRecipes.o : source/CraftingRecipes.cpp
|
||||
$(CC) $(CC_OPTIONS) source/CraftingRecipes.cpp -c $(INCLUDE) -o build/CraftingRecipes.o
|
||||
|
||||
|
||||
|
||||
build/squirrelbindings/SquirrelBindings.o : source/squirrelbindings/SquirrelBindings.cpp
|
||||
$(CC) $(CC_OPTIONS) source/squirrelbindings/SquirrelBindings.cpp -c $(INCLUDE) -o build/squirrelbindings/SquirrelBindings.o
|
||||
|
||||
build/squirrelbindings/SquirrelFunctions.o : source/squirrelbindings/SquirrelFunctions.cpp
|
||||
$(CC) $(CC_OPTIONS) source/squirrelbindings/SquirrelFunctions.cpp -c $(INCLUDE) -o build/squirrelbindings/SquirrelFunctions.o
|
||||
|
||||
build/cPlugin_Squirrel.o : source/cPlugin_Squirrel.cpp
|
||||
$(CC) $(CC_OPTIONS) source/cPlugin_Squirrel.cpp -c $(INCLUDE) -o build/cPlugin_Squirrel.o
|
||||
|
||||
build/sqstdaux.o : squirrel_3_0_1_stable/sqstdlib/sqstdaux.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdaux.cpp -c $(INCLUDE) -o build/sqstdaux.o
|
||||
build/sqstdblob.o : squirrel_3_0_1_stable/sqstdlib/sqstdblob.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdblob.cpp -c $(INCLUDE) -o build/sqstdblob.o
|
||||
build/sqstdio.o : squirrel_3_0_1_stable/sqstdlib/sqstdio.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdio.cpp -c $(INCLUDE) -o build/sqstdio.o
|
||||
build/sqstdmath.o : squirrel_3_0_1_stable/sqstdlib/sqstdmath.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdmath.cpp -c $(INCLUDE) -o build/sqstdmath.o
|
||||
build/sqstdrex.o : squirrel_3_0_1_stable/sqstdlib/sqstdrex.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdrex.cpp -c $(INCLUDE) -o build/sqstdrex.o
|
||||
build/sqstdstream.o : squirrel_3_0_1_stable/sqstdlib/sqstdstream.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdstream.cpp -c $(INCLUDE) -o build/sqstdstream.o
|
||||
build/sqstdstring.o : squirrel_3_0_1_stable/sqstdlib/sqstdstring.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdstring.cpp -c $(INCLUDE) -o build/sqstdstring.o
|
||||
build/sqstdsystem.o : squirrel_3_0_1_stable/sqstdlib/sqstdsystem.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/sqstdlib/sqstdsystem.cpp -c $(INCLUDE) -o build/sqstdsystem.o
|
||||
build/sqapi.o : squirrel_3_0_1_stable/squirrel/sqapi.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqapi.cpp -c $(INCLUDE) -o build/sqapi.o
|
||||
build/sqbaselib.o : squirrel_3_0_1_stable/squirrel/sqbaselib.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqbaselib.cpp -c $(INCLUDE) -o build/sqbaselib.o
|
||||
build/sqclass.o : squirrel_3_0_1_stable/squirrel/sqclass.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqclass.cpp -c $(INCLUDE) -o build/sqclass.o
|
||||
build/sqcompiler.o : squirrel_3_0_1_stable/squirrel/sqcompiler.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqcompiler.cpp -c $(INCLUDE) -o build/sqcompiler.o
|
||||
build/sqdebug.o : squirrel_3_0_1_stable/squirrel/sqdebug.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqdebug.cpp -c $(INCLUDE) -o build/sqdebug.o
|
||||
build/sqfuncstate.o : squirrel_3_0_1_stable/squirrel/sqfuncstate.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqfuncstate.cpp -c $(INCLUDE) -o build/sqfuncstate.o
|
||||
build/sqlexer.o : squirrel_3_0_1_stable/squirrel/sqlexer.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqlexer.cpp -c $(INCLUDE) -o build/sqlexer.o
|
||||
build/sqmem.o : squirrel_3_0_1_stable/squirrel/sqmem.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqmem.cpp -c $(INCLUDE) -o build/sqmem.o
|
||||
build/sqobject.o : squirrel_3_0_1_stable/squirrel/sqobject.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqobject.cpp -c $(INCLUDE) -o build/sqobject.o
|
||||
build/sqstate.o : squirrel_3_0_1_stable/squirrel/sqstate.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqstate.cpp -c $(INCLUDE) -o build/sqstate.o
|
||||
build/sqtable.o : squirrel_3_0_1_stable/squirrel/sqtable.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqtable.cpp -c $(INCLUDE) -o build/sqtable.o
|
||||
build/sqvm.o : squirrel_3_0_1_stable/squirrel/sqvm.cpp
|
||||
$(CC) $(CC_OPTIONS) squirrel_3_0_1_stable/squirrel/sqvm.cpp -c $(INCLUDE) -o build/sqvm.o
|
||||
|
||||
# Template: copy and delete the "# "; insert filenames
|
||||
# build/.o : source/.cpp
|
||||
# $(CC) $(CC_OPTIONS) source/.cpp -c $(INCLUDE) -o build/.o
|
||||
|
||||
|
@ -45,7 +45,7 @@ $cfile "cCuboid.h"
|
||||
$cfile "cMCLogger.h"
|
||||
$cfile "cTracer.h"
|
||||
$cfile "cGroup.h"
|
||||
$cfile "BlockArea.h"
|
||||
$cfile "cBlockArea.h"
|
||||
$cfile "packets/cPacket_Login.h"
|
||||
$cfile "packets/cPacket_BlockDig.h"
|
||||
$cfile "packets/cPacket_BlockPlace.h"
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 07/02/12 18:39:13.
|
||||
** Generated automatically by tolua++-1.0.92 on 07/08/12 16:56:12.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -54,7 +54,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
|
||||
#include "cMCLogger.h"
|
||||
#include "cTracer.h"
|
||||
#include "cGroup.h"
|
||||
#include "BlockArea.h"
|
||||
#include "cBlockArea.h"
|
||||
#include "packets/cPacket_Login.h"
|
||||
#include "packets/cPacket_BlockDig.h"
|
||||
#include "packets/cPacket_BlockPlace.h"
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 07/02/12 18:39:13.
|
||||
** Generated automatically by tolua++-1.0.92 on 07/08/12 16:56:13.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -1,140 +1,140 @@
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "SquirrelBindings.h"
|
||||
#if USE_SQUIRREL
|
||||
#pragma warning(disable:4100) // Getting A LOT of these warnings from SqPlus
|
||||
#pragma warning(disable:4127)
|
||||
|
||||
#include <sqplus/sqplus.h>
|
||||
#include <sqplus/SquirrelObject.h>
|
||||
#include <../squirrel/sqstate.h>
|
||||
#include <../squirrel/sqvm.h>
|
||||
|
||||
#include "cPlugin.h"
|
||||
#include "cPluginManager.h"
|
||||
#include "cRoot.h"
|
||||
#include "cPlayer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool SquirrelBindings::IsBound = false;
|
||||
|
||||
bool IsTopClosure( HSQUIRRELVM v )
|
||||
{
|
||||
return ( v->_stack[0]._type == OT_CLOSURE );
|
||||
}
|
||||
|
||||
class __Squirrel_Base_Class // All inheritable classes should extend this class, as it allows virtual functions to call Squirrel
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static int ConstructAndDestruct(HSQUIRRELVM v, T* a_Instance, SQRELEASEHOOK a_ReleaseHook )
|
||||
{
|
||||
LOG("ConstructAndDestruct()");
|
||||
|
||||
StackHandler sa(v);
|
||||
HSQOBJECT ho = sa.GetObjectHandle(1); // OT_INSTANCE
|
||||
SquirrelObject instance(ho);
|
||||
SqPlus::PopulateAncestry(v, instance, a_Instance);
|
||||
a_Instance->vm = v;
|
||||
a_Instance->obj = instance;
|
||||
|
||||
sq_setinstanceup(v, 1, a_Instance);
|
||||
sq_setreleasehook(v, 1, a_ReleaseHook);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
HSQUIRRELVM vm;
|
||||
SquirrelObject obj;
|
||||
};
|
||||
|
||||
class cPlugin__Squirrel : public cPlugin, public __Squirrel_Base_Class
|
||||
{
|
||||
public:
|
||||
cPlugin__Squirrel() { SetLanguage( cPlugin::E_SQUIRREL ); }
|
||||
|
||||
bool Initialize() // This is a pure virtual function, so it NEEDS an implementation on the script side or it would be an illegal instance
|
||||
{
|
||||
SqPlus::SquirrelFunction<bool> InitFunc(obj, "Initialize");
|
||||
if( !InitFunc.func.IsNull() )
|
||||
return InitFunc();
|
||||
LOGWARN("cPlugin__Squirrel::Initialize() Pure virtual function called!"); // Spam some errorz to make it clear this function needs to be implemented
|
||||
return false;
|
||||
}
|
||||
|
||||
static int constructor(HSQUIRRELVM v) { return ConstructAndDestruct( v, new cPlugin__Squirrel, SqPlus::ReleaseClassPtr<cPlugin__Squirrel>::release ); }
|
||||
|
||||
virtual bool OnChat( const char* a_Chat, cPlayer* a_Player )
|
||||
{
|
||||
if( !IsTopClosure(vm) ) // Avoid recursion (TODO: FIXME: THIS NEEDS MORE RESEARCH!)
|
||||
{ //Called from C++
|
||||
return SqPlus::SquirrelFunction<bool>(obj, "OnChat")(a_Chat, a_Player);
|
||||
}
|
||||
else // Called from Squirrel
|
||||
{
|
||||
return cPlugin::OnChat(a_Chat, a_Player);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void printFunc(HSQUIRRELVM v,const SQChar * s,...)
|
||||
{
|
||||
(void)v;
|
||||
va_list vl;
|
||||
va_start(vl,s);
|
||||
cMCLogger::GetInstance()->Log( s, vl );
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
DECLARE_INSTANCE_TYPE( cRoot );
|
||||
DECLARE_INSTANCE_TYPE( cPluginManager );
|
||||
DECLARE_ENUM_TYPE( cPluginManager::PluginHook );
|
||||
DECLARE_INSTANCE_TYPE( cPlugin );
|
||||
DECLARE_INSTANCE_TYPE( cPlugin__Squirrel );
|
||||
|
||||
DECLARE_INSTANCE_TYPE( cEntity );
|
||||
DECLARE_INSTANCE_TYPE( cPawn );
|
||||
DECLARE_INSTANCE_TYPE( cPlayer );
|
||||
|
||||
void SquirrelBindings::Bind( HSQUIRRELVM a_SquirrelVM )
|
||||
{
|
||||
IsBound = true;
|
||||
|
||||
sq_setprintfunc(a_SquirrelVM, printFunc, printFunc);
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cEntity>("cEntity");
|
||||
SqPlus::SQClassDefNoConstructor<cPawn, cEntity>("cPawn", "cEntity");
|
||||
SqPlus::SQClassDefNoConstructor<cPlayer, cPawn>("cPlayer", "cPawn"). // All NoConstructor because they need a custom one
|
||||
func(&cPlayer::GetName, "GetName");
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cPlugin>("cPlugin").
|
||||
func(&cPlugin::SetName, "SetName").
|
||||
func(&cPlugin::GetName, "GetName").
|
||||
func(&cPlugin::GetVersion, "GetVersion").
|
||||
func(&cPlugin::OnChat, "OnChat");
|
||||
|
||||
|
||||
SqPlus::SQClassDef<cPlugin__Squirrel, cPlugin>("cPlugin__Squirrel", "cPlugin").
|
||||
staticFunc(&cPlugin__Squirrel::constructor, "constructor");
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cRoot>("cRoot").
|
||||
staticFunc(&cRoot::Get, "Get").
|
||||
func(static_cast<cPluginManager* (__thiscall cRoot::*)(void)>(&cRoot::GetPluginManager), "GetPluginManager");
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cPluginManager>("cPluginManager").
|
||||
overloadFunc<bool (cPluginManager::*)(cPlugin*)>(&cPluginManager::AddPlugin, "AddPlugin").
|
||||
func(&cPluginManager::GetPlugin, "GetPlugin").
|
||||
func(&cPluginManager::AddHook, "AddHook").
|
||||
enumInt( cPluginManager::E_PLUGIN_CHAT, "E_PLUGIN_CHAT");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
||||
|
||||
#include "SquirrelBindings.h"
|
||||
#if USE_SQUIRREL
|
||||
//#pragma warning(disable:4100) // Getting A LOT of these warnings from SqPlus
|
||||
//#pragma warning(disable:4127)
|
||||
|
||||
#include <sqplus/sqplus.h>
|
||||
#include <sqplus/SquirrelObject.h>
|
||||
#include <../squirrel/sqstate.h>
|
||||
#include <../squirrel/sqvm.h>
|
||||
|
||||
#include "cPlugin.h"
|
||||
#include "cPluginManager.h"
|
||||
#include "cRoot.h"
|
||||
#include "cPlayer.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool SquirrelBindings::IsBound = false;
|
||||
|
||||
bool IsTopClosure( HSQUIRRELVM v )
|
||||
{
|
||||
return ( v->_stack[0]._type == OT_CLOSURE );
|
||||
}
|
||||
|
||||
class __Squirrel_Base_Class // All inheritable classes should extend this class, as it allows virtual functions to call Squirrel
|
||||
{
|
||||
public:
|
||||
template<typename T>
|
||||
static int ConstructAndDestruct(HSQUIRRELVM v, T* a_Instance, SQRELEASEHOOK a_ReleaseHook )
|
||||
{
|
||||
LOG("ConstructAndDestruct()");
|
||||
|
||||
StackHandler sa(v);
|
||||
HSQOBJECT ho = sa.GetObjectHandle(1); // OT_INSTANCE
|
||||
SquirrelObject instance(ho);
|
||||
SqPlus::PopulateAncestry(v, instance, a_Instance);
|
||||
a_Instance->vm = v;
|
||||
a_Instance->obj = instance;
|
||||
|
||||
sq_setinstanceup(v, 1, a_Instance);
|
||||
sq_setreleasehook(v, 1, a_ReleaseHook);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
HSQUIRRELVM vm;
|
||||
SquirrelObject obj;
|
||||
};
|
||||
|
||||
class cPlugin__Squirrel : public cPlugin, public __Squirrel_Base_Class
|
||||
{
|
||||
public:
|
||||
cPlugin__Squirrel() { SetLanguage( cPlugin::E_SQUIRREL ); }
|
||||
|
||||
bool Initialize() // This is a pure virtual function, so it NEEDS an implementation on the script side or it would be an illegal instance
|
||||
{
|
||||
SqPlus::SquirrelFunction<bool> InitFunc(obj, "Initialize");
|
||||
if( !InitFunc.func.IsNull() )
|
||||
return InitFunc();
|
||||
LOGWARN("cPlugin__Squirrel::Initialize() Pure virtual function called!"); // Spam some errorz to make it clear this function needs to be implemented
|
||||
return false;
|
||||
}
|
||||
|
||||
static int constructor(HSQUIRRELVM v) { return ConstructAndDestruct( v, new cPlugin__Squirrel, SqPlus::ReleaseClassPtr<cPlugin__Squirrel>::release ); }
|
||||
|
||||
virtual bool OnChat( const char* a_Chat, cPlayer* a_Player )
|
||||
{
|
||||
if( !IsTopClosure(vm) ) // Avoid recursion (TODO: FIXME: THIS NEEDS MORE RESEARCH!)
|
||||
{ //Called from C++
|
||||
return SqPlus::SquirrelFunction<bool>(obj, "OnChat")(a_Chat, a_Player);
|
||||
}
|
||||
else // Called from Squirrel
|
||||
{
|
||||
return cPlugin::OnChat(a_Chat, a_Player);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static void printFunc(HSQUIRRELVM v,const SQChar * s,...)
|
||||
{
|
||||
(void)v;
|
||||
va_list vl;
|
||||
va_start(vl,s);
|
||||
cMCLogger::GetInstance()->Log( s, vl );
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
DECLARE_INSTANCE_TYPE( cRoot );
|
||||
DECLARE_INSTANCE_TYPE( cPluginManager );
|
||||
DECLARE_ENUM_TYPE( cPluginManager::PluginHook );
|
||||
DECLARE_INSTANCE_TYPE( cPlugin );
|
||||
DECLARE_INSTANCE_TYPE( cPlugin__Squirrel );
|
||||
|
||||
DECLARE_INSTANCE_TYPE( cEntity );
|
||||
DECLARE_INSTANCE_TYPE( cPawn );
|
||||
DECLARE_INSTANCE_TYPE( cPlayer );
|
||||
|
||||
void SquirrelBindings::Bind( HSQUIRRELVM a_SquirrelVM )
|
||||
{
|
||||
IsBound = true;
|
||||
|
||||
sq_setprintfunc(a_SquirrelVM, printFunc, printFunc);
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cEntity>("cEntity");
|
||||
SqPlus::SQClassDefNoConstructor<cPawn, cEntity>("cPawn", "cEntity");
|
||||
SqPlus::SQClassDefNoConstructor<cPlayer, cPawn>("cPlayer", "cPawn"). // All NoConstructor because they need a custom one
|
||||
func(&cPlayer::GetName, "GetName");
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cPlugin>("cPlugin").
|
||||
func(&cPlugin::SetName, "SetName").
|
||||
func(&cPlugin::GetName, "GetName").
|
||||
func(&cPlugin::GetVersion, "GetVersion").
|
||||
func(&cPlugin::OnChat, "OnChat");
|
||||
|
||||
|
||||
SqPlus::SQClassDef<cPlugin__Squirrel, cPlugin>("cPlugin__Squirrel", "cPlugin").
|
||||
staticFunc(&cPlugin__Squirrel::constructor, "constructor");
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cRoot>("cRoot").
|
||||
staticFunc(&cRoot::Get, "Get").
|
||||
func(static_cast<cPluginManager* (__thiscall cRoot::*)(void)>(&cRoot::GetPluginManager), "GetPluginManager");
|
||||
|
||||
|
||||
SqPlus::SQClassDefNoConstructor<cPluginManager>("cPluginManager").
|
||||
overloadFunc<bool (cPluginManager::*)(cPlugin*)>(&cPluginManager::AddPlugin, "AddPlugin").
|
||||
func(&cPluginManager::GetPlugin, "GetPlugin").
|
||||
func(&cPluginManager::AddHook, "AddHook").
|
||||
enumInt( cPluginManager::E_PLUGIN_CHAT, "E_PLUGIN_CHAT");
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#define USE_SQUIRREL 0
|
||||
|
||||
#if USE_SQUIRREL
|
||||
|
||||
struct SQVM;
|
||||
class SquirrelBindings
|
||||
{
|
||||
public:
|
||||
static void Bind( SQVM* a_SquirrelVM );
|
||||
static bool IsBound;
|
||||
};
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
|
||||
#define USE_SQUIRREL 1
|
||||
|
||||
#if USE_SQUIRREL
|
||||
|
||||
struct SQVM;
|
||||
class SquirrelBindings
|
||||
{
|
||||
public:
|
||||
static void Bind( SQVM* a_SquirrelVM );
|
||||
static bool IsBound;
|
||||
};
|
||||
|
||||
#endif
|
@ -5,7 +5,7 @@
|
||||
// The object also supports writing the blockdata back into cWorld, even into other coords
|
||||
|
||||
#include "Globals.h"
|
||||
#include "BlockArea.h"
|
||||
#include "cBlockArea.h"
|
||||
#include "cWorld.h"
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "cBlockToPickup.h"
|
||||
#include "MersenneTwister.h"
|
||||
#include "cPlayer.h"
|
||||
#include "BlockArea.h"
|
||||
#include "cBlockArea.h"
|
||||
#include "cPluginManager.h"
|
||||
|
||||
#include "packets/cPacket_DestroyEntity.h"
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "cPlugin.h"
|
||||
#include "cPlugin_Lua.h"
|
||||
#include "cPlugin_NewLua.h"
|
||||
#include "cPlugin_Squirrel.h"
|
||||
#include "cWebAdmin.h"
|
||||
#include "cItem.h"
|
||||
#include "cRoot.h"
|
||||
@ -12,10 +13,12 @@
|
||||
#include "../iniFile/iniFile.h"
|
||||
#include "tolua++.h"
|
||||
|
||||
#include "SquirrelBindings.h"
|
||||
#include "squirrelbindings/SquirrelBindings.h"
|
||||
#include "squirrelbindings/SquirrelFunctions.h"
|
||||
|
||||
#if USE_SQUIRREL
|
||||
#pragma warning(disable:4100;disable:4127;disable:4510;disable:4610;disable:4244;disable:4512) // Getting A LOT of these warnings from SqPlus
|
||||
#include <sqplus/sqplus.h>
|
||||
|
||||
#pragma warning(default:4100;default:4127;default:4510;default:4610;default:4244;default:4512)
|
||||
#endif
|
||||
|
||||
@ -70,11 +73,8 @@ void cPluginManager::ReloadPluginsNow()
|
||||
UnloadPluginsNow();
|
||||
|
||||
#if USE_SQUIRREL
|
||||
if( !SquirrelBindings::IsBound ) // Can only do this once apparently, or we're making ambiguous calls in the script
|
||||
{
|
||||
SquirrelVM::Init();
|
||||
SquirrelBindings::Bind( SquirrelVM::GetVMPtr() );
|
||||
}
|
||||
CloseSquirrelVM();
|
||||
OpenSquirrelVM();
|
||||
#endif // USE_SQUIRREL
|
||||
|
||||
cIniFile IniFile("settings.ini");
|
||||
@ -129,26 +129,11 @@ void cPluginManager::ReloadPluginsNow()
|
||||
if( !PluginFile.empty() )
|
||||
{
|
||||
LOGINFO("Loading Squirrel plugin: %s", PluginFile.c_str() );
|
||||
try
|
||||
{
|
||||
SquirrelObject SquirrelScript = SquirrelVM::CompileScript( (AString("Plugins/") + PluginFile + ".nut").c_str() );
|
||||
try
|
||||
{
|
||||
SquirrelVM::RunScript( SquirrelScript );
|
||||
}
|
||||
catch (SquirrelError & e)
|
||||
{
|
||||
LOGERROR("SquirrelScript error: %s, %s\n", e.desc, "SquirrelVM::RunScript");
|
||||
}
|
||||
}
|
||||
catch (SquirrelError & e)
|
||||
{
|
||||
LOGERROR("SquirrelScript error: %s, %s\n", e.desc, "SquirrelVM::CompileScript");
|
||||
}
|
||||
|
||||
this->AddPlugin(new cPlugin_Squirrel(PluginFile.c_str()));
|
||||
}
|
||||
}
|
||||
#endif // USE_SQUIRREL
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +180,7 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
|
||||
if (a_Hook == HOOK_CHAT)
|
||||
{
|
||||
if (a_NumArgs != 2)
|
||||
{
|
||||
{
|
||||
return false;
|
||||
}
|
||||
va_list argptr;
|
||||
@ -221,6 +206,7 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
352
source/cPlugin_Squirrel.cpp
Normal file
352
source/cPlugin_Squirrel.cpp
Normal file
@ -0,0 +1,352 @@
|
||||
#include "Globals.h"
|
||||
#include "cPlugin_Squirrel.h"
|
||||
#include "squirrelbindings/SquirrelFunctions.h"
|
||||
#include "squirrelbindings/SquirrelBindings.h"
|
||||
#include "squirrelbindings/cSquirrelBaseClass.h"
|
||||
|
||||
|
||||
cPlugin_Squirrel::cPlugin_Squirrel( const char* a_PluginName )
|
||||
{
|
||||
SetLanguage( cPlugin::E_SQUIRREL );
|
||||
m_PluginName = a_PluginName;
|
||||
}
|
||||
|
||||
cPlugin_Squirrel::~cPlugin_Squirrel()
|
||||
{
|
||||
delete m_PluginName;
|
||||
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);
|
||||
|
||||
m_Plugin->GetFunction("OnDisable").Execute();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlugin_Squirrel::Tick(float a_Dt)
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
m_Plugin->GetFunction("OnTick").Execute(a_Dt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnCollectItem").Evaluate<bool>(a_Pickup, a_Player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnDisconnect(const AString & a_Reason, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
|
||||
return m_Plugin->GetFunction("OnDisconnect").Evaluate<bool>(a_Reason, a_Player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnBlockPlace").Evaluate<bool>(a_PacketData, a_Player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnBlockDig").Evaluate<bool>(a_PacketData, a_Player, a_PickupItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnChat( const char* a_Chat, cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Chat, a_Player);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnLogin( cPacket_Login* a_PacketData )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnLogin").Evaluate<bool>(a_PacketData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlugin_Squirrel::OnPlayerSpawn( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnPlayerSpawn").Execute(a_Player);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnPlayerJoin( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnPlayerJoin").Evaluate<bool>(a_Player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlugin_Squirrel::OnPlayerMove( cPlayer* a_Player )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnPlayerMove").Execute(a_Player);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cPlugin_Squirrel::OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
return m_Plugin->GetFunction("OnTakeDamage")(a_Pawn, a_TakeDamageInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnKilled( cPawn* a_Killed, cEntity* a_Killer )
|
||||
{
|
||||
cCSLock Lock( m_CriticalSection );
|
||||
|
||||
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);
|
||||
|
||||
return m_Plugin->GetFunction("OnChunkGenerated")(a_World, a_ChunkX, a_ChunkZ);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_Squirrel::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
|
||||
|
||||
return m_Plugin->GetFunction("OnUpdatingSign")
|
||||
.Evaluate<bool>(
|
||||
a_World,
|
||||
a_BlockX,
|
||||
a_BlockY,
|
||||
a_BlockZ,
|
||||
a_Line1,
|
||||
a_Line2,
|
||||
a_Line3,
|
||||
a_Line4
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
{
|
||||
return m_Plugin->GetFunction("OnUpdatedSign")
|
||||
.Evaluate<bool>(
|
||||
a_World,
|
||||
a_BlockX,
|
||||
a_BlockY,
|
||||
a_BlockZ,
|
||||
a_Line1,
|
||||
a_Line2,
|
||||
a_Line3,
|
||||
a_Line4
|
||||
);
|
||||
}
|
42
source/cPlugin_Squirrel.h
Normal file
42
source/cPlugin_Squirrel.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include "cPlugin.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);
|
||||
|
||||
bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
|
||||
bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
|
||||
bool OnBlockPlace (cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ) override;
|
||||
bool OnBlockDig (cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) override;
|
||||
bool OnChat (const char* a_Chat, cPlayer* a_Player ) override;
|
||||
bool OnLogin (cPacket_Login* a_PacketData ) override;
|
||||
void OnPlayerSpawn (cPlayer* a_Player ) override;
|
||||
bool OnPlayerJoin (cPlayer* a_Player ) override;
|
||||
void OnPlayerMove (cPlayer* a_Player ) override;
|
||||
void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
|
||||
bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
|
||||
void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
|
||||
bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
|
||||
bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
|
||||
bool OnWeatherChanged (cWorld * a_World) override;
|
||||
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) override;
|
||||
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) override;
|
||||
|
||||
protected:
|
||||
const char * m_PluginName;
|
||||
cCriticalSection m_CriticalSection;
|
||||
SquirrelObject *m_Plugin;
|
||||
};
|
@ -19,6 +19,5 @@ public:
|
||||
default:
|
||||
return 0xf;
|
||||
};
|
||||
return 0xf;
|
||||
} //tolua_export
|
||||
}; //tolua_export
|
@ -6,16 +6,17 @@
|
||||
#include <exception> //std::exception
|
||||
#include <csignal> //std::signal
|
||||
#include <stdlib.h> //exit()
|
||||
#include "squirrelbindings/SquirrelFunctions.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <dbghelp.h>
|
||||
#endif // _WIN32
|
||||
|
||||
#include "SquirrelBindings.h"
|
||||
#include "squirrelbindings/SquirrelBindings.h"
|
||||
#if USE_SQUIRREL
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4100;disable:4127;disable:4510;disable:4610;disable:4244;disable:4512) // Getting A LOT of these warnings from SqPlus
|
||||
#include <sqplus/sqplus.h>
|
||||
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
@ -189,7 +190,7 @@ int main( int argc, char **argv )
|
||||
}
|
||||
|
||||
#if USE_SQUIRREL
|
||||
SquirrelVM::Shutdown();
|
||||
CloseSquirrelVM();
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER) && defined(_DEBUG) && defined(ENABLE_LEAK_FINDER)
|
||||
|
52
source/squirrelbindings/SquirrelBindings.cpp
Normal file
52
source/squirrelbindings/SquirrelBindings.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
#include "Globals.h"
|
||||
#include "SquirrelBindings.h"
|
||||
#include "SquirrelFunctions.h"
|
||||
|
||||
#include "cSquirrelBaseClass.h"
|
||||
|
||||
#include "../cPlayer.h"
|
||||
|
||||
using namespace Sqrat;
|
||||
|
||||
|
||||
|
||||
void BindSquirrel(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable()
|
||||
.Bind("Plugin", Class<cSquirrelBaseClass>()
|
||||
.Func("AddHook", &cSquirrelBaseClass::AddHook)
|
||||
);
|
||||
RootTable().Bind("cPlayer", Class<cPlayer, NoConstructor>()
|
||||
.Func("GetName", &cPlayer::GetName)
|
||||
);
|
||||
|
||||
|
||||
RootTable().Func("print", &sqPrint);
|
||||
|
||||
|
||||
ConstTable().Enum("Hook", Enumeration()
|
||||
.Const("Tick", cPluginManager::HOOK_TICK)
|
||||
.Const("Chat", cPluginManager::HOOK_CHAT)
|
||||
.Const("CollectItem", cPluginManager::HOOK_COLLECT_ITEM)
|
||||
.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));
|
||||
|
||||
}
|
13
source/squirrelbindings/SquirrelBindings.h
Normal file
13
source/squirrelbindings/SquirrelBindings.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
#define USE_SQUIRREL 1
|
||||
|
||||
#if USE_SQUIRREL
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <sqrat.h>
|
||||
|
||||
void BindSquirrel(HSQUIRRELVM vm);
|
||||
|
||||
#endif
|
65
source/squirrelbindings/SquirrelFunctions.cpp
Normal file
65
source/squirrelbindings/SquirrelFunctions.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
|
||||
#include "Globals.h"
|
||||
#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);
|
||||
}
|
6
source/squirrelbindings/SquirrelFunctions.h
Normal file
6
source/squirrelbindings/SquirrelFunctions.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include <sqrat.h>
|
||||
HSQUIRRELVM OpenSquirrelVM();
|
||||
void CloseSquirrelVM();
|
||||
|
||||
void sqPrint(SQChar * text);
|
24
source/squirrelbindings/SquirrelObject.h
Normal file
24
source/squirrelbindings/SquirrelObject.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <sqrat.h>
|
||||
|
||||
class SquirrelObject
|
||||
{
|
||||
public:
|
||||
SquirrelObject(Sqrat::Object a_Obj)
|
||||
{
|
||||
m_SquirrelObject = a_Obj;
|
||||
}
|
||||
|
||||
Sqrat::Function GetFunction(const char *methodName)
|
||||
{
|
||||
if(m_SquirrelObject.IsNull())
|
||||
return Sqrat::Function();
|
||||
|
||||
Sqrat::Function method(m_SquirrelObject, methodName);
|
||||
return method;
|
||||
}
|
||||
|
||||
protected:
|
||||
Sqrat::Object m_SquirrelObject;
|
||||
|
||||
};
|
29
source/squirrelbindings/cSquirrelBaseClass.h
Normal file
29
source/squirrelbindings/cSquirrelBaseClass.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include "SquirrelBindings.h"
|
||||
#include "../cPlugin_Squirrel.h"
|
||||
#include "../cPluginManager.h"
|
||||
#include "cRoot.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);
|
||||
}
|
||||
|
||||
protected:
|
||||
cPlugin_Squirrel *m_Instance;
|
||||
};
|
@ -1,382 +1,382 @@
|
||||
#include "sqplus.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_OPT
|
||||
#define SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
#include "SqPlusSmartPointer.h"
|
||||
#endif
|
||||
|
||||
namespace SqPlus {
|
||||
|
||||
static int getVarInfo(StackHandler & sa,VarRefPtr & vr) {
|
||||
HSQOBJECT htable = sa.GetObjectHandle(1);
|
||||
SquirrelObject table(htable);
|
||||
const SQChar * el = sa.GetString(2);
|
||||
ScriptStringVar256 varNameTag;
|
||||
getVarNameTag(varNameTag,sizeof(varNameTag),el);
|
||||
SQUserPointer data=0;
|
||||
if (!table.RawGetUserData(varNameTag,&data)) {
|
||||
return sa.ThrowError(_SC("getVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
|
||||
}
|
||||
vr = (VarRefPtr)data;
|
||||
return SQ_OK;
|
||||
} // getVarInfo
|
||||
|
||||
static int getInstanceVarInfo(StackHandler & sa,VarRefPtr & vr,SQUserPointer & data) {
|
||||
HSQOBJECT ho = sa.GetObjectHandle(1);
|
||||
SquirrelObject instance(ho);
|
||||
const SQChar * el = sa.GetString(2);
|
||||
ScriptStringVar256 varNameTag;
|
||||
getVarNameTag(varNameTag,sizeof(varNameTag),el);
|
||||
SQUserPointer ivrData=0;
|
||||
if (!instance.RawGetUserData(varNameTag,&ivrData)) {
|
||||
return sa.ThrowError(_SC("getInstanceVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
|
||||
}
|
||||
vr = (VarRefPtr)ivrData;
|
||||
|
||||
char * up;
|
||||
if (!(vr->m_access & (VAR_ACCESS_STATIC|VAR_ACCESS_CONSTANT))) {
|
||||
SQUserPointer typetag;
|
||||
instance.GetTypeTag(&typetag);
|
||||
|
||||
#if defined(SQ_USE_CLASS_INHERITANCE)
|
||||
if (typetag != vr->instanceType) {
|
||||
SquirrelObject typeTable = instance.GetValue(SQ_CLASS_OBJECT_TABLE_NAME);
|
||||
up = (char *)typeTable.GetUserPointer(INT((size_t)vr->instanceType)); // <TODO> 64-bit compatible version.
|
||||
if (!up) {
|
||||
throw SquirrelError(_SC("Invalid Instance Type"));
|
||||
}
|
||||
} else {
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
} // if
|
||||
|
||||
#elif defined(SQ_USE_CLASS_INHERITANCE_SIMPLE)
|
||||
ClassTypeBase *ctb = (ClassTypeBase*)vr->instanceType;
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
// Walk base classes until type tag match, adjust for inheritence offset
|
||||
while(ctb && typetag!=ctb) {
|
||||
up = (char*)up - ctb->m_offset;
|
||||
ctb = ctb->m_pbase;
|
||||
}
|
||||
if (!ctb) {
|
||||
throw SquirrelError(_SC("Invalid Instance Type"));
|
||||
}
|
||||
#else
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_OPT
|
||||
#define SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
#include "SqPlusSmartPointer.h"
|
||||
#endif
|
||||
|
||||
up += (size_t)vr->offsetOrAddrOrConst; // Offset
|
||||
} else {
|
||||
up = (char *)vr->offsetOrAddrOrConst; // Address
|
||||
} // if
|
||||
data = up;
|
||||
return SQ_OK;
|
||||
} // getInstanceVarInfo
|
||||
|
||||
|
||||
// If not static/global, message can (and will) disappear before arriving at catch (G++)
|
||||
static ScriptStringVar256 g_msg_throw;
|
||||
|
||||
static int setVar(StackHandler & sa,VarRef * vr,void * data) {
|
||||
if (vr->m_access & (VAR_ACCESS_READ_ONLY|VAR_ACCESS_CONSTANT)) {
|
||||
const SQChar * el = sa.GetString(2);
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to constant: %s"),el);
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // if
|
||||
switch (vr->m_type) {
|
||||
case TypeInfo<INT>::TypeID: {
|
||||
INT * val = (INT *)data; // Address
|
||||
if (val) {
|
||||
INT v = sa.GetInt(3);
|
||||
// Support for different int sizes
|
||||
switch( vr->m_size ) {
|
||||
case 1: v = (*(char*)val = (char)v); break;
|
||||
case 2: v = (*(short*)val = (short)v); break;
|
||||
#ifdef _SQ64
|
||||
case 4: v = (*(int*)val = (int)v); break;
|
||||
#endif
|
||||
default: *val = v;
|
||||
}
|
||||
return sa.Return(v);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<unsigned>::TypeID: {
|
||||
unsigned * val = (unsigned *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetInt(3);
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<FLOAT>::TypeID: {
|
||||
FLOAT * val = (FLOAT *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetFloat(3);
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<bool>::TypeID: {
|
||||
bool * val = (bool *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetBool(3) ? true : false;
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case VAR_TYPE_INSTANCE: {
|
||||
HSQUIRRELVM v = sa.GetVMPtr();
|
||||
SQUserPointer src = sa.GetInstanceUp(3,(SQUserPointer)vr->varType); // Effectively performs: ClassType<>::type() == ClassType<>().
|
||||
if (!src) {
|
||||
throw SquirrelError(_SC("INSTANCE type assignment mismatch"));
|
||||
}
|
||||
vr->varType->vgetCopyFunc()(data,src);
|
||||
return 0;
|
||||
}
|
||||
case TypeInfo<SQUserPointer>::TypeID: {
|
||||
const SQChar * el = sa.GetString(2);
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to an SQUserPointer: %s"),el);
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // case
|
||||
case TypeInfo<ScriptStringVarBase>::TypeID: {
|
||||
ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
|
||||
if (val) {
|
||||
const SQChar * strVal = sa.GetString(3);
|
||||
if (strVal) {
|
||||
*val = strVal;
|
||||
return sa.Return(val->s);
|
||||
} // if
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
case TypeInfo<std::string>::TypeID: {
|
||||
std::string *val = (std::string*)data; // Address
|
||||
if (val) {
|
||||
const SQChar *strVal = sa.GetString(3);
|
||||
if (strVal) {
|
||||
*val = strVal;
|
||||
return sa.Return(val->c_str());
|
||||
} // if
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
#endif
|
||||
} // switch
|
||||
return SQ_ERROR;
|
||||
} // setVar
|
||||
|
||||
static int getVar(StackHandler & sa,VarRef * vr,void * data) {
|
||||
switch (vr->m_type) {
|
||||
case TypeInfo<INT>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
if (data) {
|
||||
INT v;
|
||||
// Support for different int sizes
|
||||
switch( vr->m_size ){
|
||||
case 1: v = *(char*)data; break;
|
||||
case 2: v = *(short*)data; break;
|
||||
#ifdef _SQ64
|
||||
case 4: v = *(int*)data; break;
|
||||
#endif
|
||||
default: v = *(INT*)data;
|
||||
}
|
||||
return sa.Return(v);
|
||||
} // if
|
||||
} else {
|
||||
INT * val = (INT *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<unsigned>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
unsigned * val = (unsigned *)data; // Address
|
||||
if (val){
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
}
|
||||
} else {
|
||||
unsigned * val = (unsigned *)&data; // Constant value
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<FLOAT>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
FLOAT * val = (FLOAT *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
} else {
|
||||
FLOAT * val = (FLOAT *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<bool>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
bool * val = (bool *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
} else {
|
||||
bool * val = (bool *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case VAR_TYPE_INSTANCE:
|
||||
if (!CreateNativeClassInstance(sa.GetVMPtr(),vr->varType->GetTypeName(),data,0)) { // data = address. Allocates memory.
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("getVar(): Could not create instance: %s"),vr->varType->GetTypeName());
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // if
|
||||
return 1;
|
||||
case TypeInfo<SQUserPointer>::TypeID:
|
||||
return sa.Return(data); // The address of member variable, not the variable itself.
|
||||
case TypeInfo<ScriptStringVarBase>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(val->s);
|
||||
} // if
|
||||
} else {
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'ScriptStringVarBase' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<const SQChar *>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
if( vr->m_access==VAR_ACCESS_READ_WRITE )
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'const SQChar *' without VAR_ACCESS_CONSTANT"));
|
||||
// It is OK to read from a SQChar* if requested
|
||||
return sa.Return(*(const SQChar **)data); // Address
|
||||
} else {
|
||||
return sa.Return((const SQChar *)data); // Address
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
#ifdef SQPLUS_SUPPORT_STD_STRING
|
||||
case TypeInfo<std::string>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
std::string *val = (std::string *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(val->c_str());
|
||||
}
|
||||
} else {
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'std::string' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
#endif
|
||||
} // switch
|
||||
return SQ_ERROR;
|
||||
} // getVar
|
||||
|
||||
// === Global Vars ===
|
||||
|
||||
int setVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_TABLE) {
|
||||
VarRefPtr vr;
|
||||
int res = getVarInfo(sa,vr);
|
||||
if (res != SQ_OK) return res;
|
||||
return setVar(sa,vr,vr->offsetOrAddrOrConst);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // setVarFunc
|
||||
|
||||
int getVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_TABLE) {
|
||||
VarRefPtr vr;
|
||||
int res = getVarInfo(sa,vr);
|
||||
if (res != SQ_OK) return res;
|
||||
return getVar(sa,vr,vr->offsetOrAddrOrConst);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // getVarFunc
|
||||
|
||||
// === Instance Vars ===
|
||||
|
||||
int setInstanceVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_INSTANCE) {
|
||||
VarRefPtr vr;
|
||||
void * data;
|
||||
int res = getInstanceVarInfo(sa,vr,data);
|
||||
if (res != SQ_OK) return res;
|
||||
return setVar(sa,vr,data);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // setInstanceVarFunc
|
||||
|
||||
int getInstanceVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_INSTANCE) {
|
||||
VarRefPtr vr;
|
||||
void * data;
|
||||
int res = getInstanceVarInfo(sa,vr,data);
|
||||
if (res != SQ_OK) return res;
|
||||
return getVar(sa,vr,data);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // getInstanceVarFunc
|
||||
|
||||
// === Classes ===
|
||||
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelObject & newClass,SQUserPointer classType,const SQChar * name,const SQChar * baseName) {
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,name,-1);
|
||||
if (baseName) {
|
||||
sq_pushstring(v,baseName,-1);
|
||||
if (SQ_FAILED(sq_get(v,-3))) { // Make sure the base exists if specified by baseName.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
} // if
|
||||
if (SQ_FAILED(sq_newclass(v,baseName ? 1 : 0))) { // Will inherit from base class on stack from sq_get() above.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
newClass.AttachToStackObject(-1);
|
||||
sq_settypetag(v,-1,classType);
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return TRUE;
|
||||
} // CreateClass
|
||||
|
||||
SquirrelObject RegisterClassType(HSQUIRRELVM v,const SQChar * scriptClassName,SQUserPointer classType,SQFUNCTION constructor) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
int top = sq_gettop(v);
|
||||
SquirrelObject newClass;
|
||||
if (CreateClass(v,newClass,classType,scriptClassName)) {
|
||||
SquirrelVM::CreateFunction(newClass,constructor,_SC("constructor"));
|
||||
} // if
|
||||
sq_settop(v,top);
|
||||
return newClass;
|
||||
} // RegisterClassType
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// GCC sometimes has problems with finding inline functions at link time
|
||||
// (that also have a template definition). To solve the problem,
|
||||
// non-inlines goes here.
|
||||
#ifdef GCC_INLINE_WORKAROUND
|
||||
# include "SqPlusFunctionCallImpl.h"
|
||||
#endif // GCC_INLINE_WORKAROUND
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace SqPlus
|
||||
|
||||
#include "sqplus.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_OPT
|
||||
#define SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
#include "SqPlusSmartPointer.h"
|
||||
#endif
|
||||
|
||||
namespace SqPlus {
|
||||
|
||||
static int getVarInfo(StackHandler & sa,VarRefPtr & vr) {
|
||||
HSQOBJECT htable = sa.GetObjectHandle(1);
|
||||
SquirrelObject table(htable);
|
||||
const SQChar * el = sa.GetString(2);
|
||||
ScriptStringVar256 varNameTag;
|
||||
getVarNameTag(varNameTag,sizeof(varNameTag),el);
|
||||
SQUserPointer data=0;
|
||||
if (!table.RawGetUserData(varNameTag,&data)) {
|
||||
return sa.ThrowError(_SC("getVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
|
||||
}
|
||||
vr = (VarRefPtr)data;
|
||||
return SQ_OK;
|
||||
} // getVarInfo
|
||||
|
||||
static int getInstanceVarInfo(StackHandler & sa,VarRefPtr & vr,SQUserPointer & data) {
|
||||
HSQOBJECT ho = sa.GetObjectHandle(1);
|
||||
SquirrelObject instance(ho);
|
||||
const SQChar * el = sa.GetString(2);
|
||||
ScriptStringVar256 varNameTag;
|
||||
getVarNameTag(varNameTag,sizeof(varNameTag),el);
|
||||
SQUserPointer ivrData=0;
|
||||
if (!instance.RawGetUserData(varNameTag,&ivrData)) {
|
||||
return sa.ThrowError(_SC("getInstanceVarInfo: Could not retrieve UserData")); // Results in variable not being found error.
|
||||
}
|
||||
vr = (VarRefPtr)ivrData;
|
||||
|
||||
char * up;
|
||||
if (!(vr->m_access & (VAR_ACCESS_STATIC|VAR_ACCESS_CONSTANT))) {
|
||||
SQUserPointer typetag;
|
||||
instance.GetTypeTag(&typetag);
|
||||
|
||||
#if defined(SQ_USE_CLASS_INHERITANCE)
|
||||
if (typetag != vr->instanceType) {
|
||||
SquirrelObject typeTable = instance.GetValue(SQ_CLASS_OBJECT_TABLE_NAME);
|
||||
up = (char *)typeTable.GetUserPointer(INT((size_t)vr->instanceType)); // <TODO> 64-bit compatible version.
|
||||
if (!up) {
|
||||
throw SquirrelError(_SC("Invalid Instance Type"));
|
||||
}
|
||||
} else {
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
} // if
|
||||
|
||||
#elif defined(SQ_USE_CLASS_INHERITANCE_SIMPLE)
|
||||
ClassTypeBase *ctb = (ClassTypeBase*)vr->instanceType;
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
// Walk base classes until type tag match, adjust for inheritence offset
|
||||
while(ctb && typetag!=ctb) {
|
||||
up = (char*)up - ctb->m_offset;
|
||||
ctb = ctb->m_pbase;
|
||||
}
|
||||
if (!ctb) {
|
||||
throw SquirrelError(_SC("Invalid Instance Type"));
|
||||
}
|
||||
#else
|
||||
up = (char *)instance.GetInstanceUP(0);
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_OPT
|
||||
#define SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
#include "SqPlusSmartPointer.h"
|
||||
#endif
|
||||
|
||||
up += (size_t)vr->offsetOrAddrOrConst; // Offset
|
||||
} else {
|
||||
up = (char *)vr->offsetOrAddrOrConst; // Address
|
||||
} // if
|
||||
data = up;
|
||||
return SQ_OK;
|
||||
} // getInstanceVarInfo
|
||||
|
||||
|
||||
// If not static/global, message can (and will) disappear before arriving at catch (G++)
|
||||
static ScriptStringVar256 g_msg_throw;
|
||||
|
||||
static int setVar(StackHandler & sa,VarRef * vr,void * data) {
|
||||
if (vr->m_access & (VAR_ACCESS_READ_ONLY|VAR_ACCESS_CONSTANT)) {
|
||||
const SQChar * el = sa.GetString(2);
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to constant: %s"),el);
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // if
|
||||
switch (vr->m_type) {
|
||||
case TypeInfo<INT>::TypeID: {
|
||||
INT * val = (INT *)data; // Address
|
||||
if (val) {
|
||||
INT v = sa.GetInt(3);
|
||||
// Support for different int sizes
|
||||
switch( vr->m_size ) {
|
||||
case 1: v = (*(char*)val = (char)v); break;
|
||||
case 2: v = (*(short*)val = (short)v); break;
|
||||
#ifdef _SQ64
|
||||
case 4: v = (*(int*)val = (int)v); break;
|
||||
#endif
|
||||
default: *val = v;
|
||||
}
|
||||
return sa.Return(v);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<unsigned>::TypeID: {
|
||||
unsigned * val = (unsigned *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetInt(3);
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<FLOAT>::TypeID: {
|
||||
FLOAT * val = (FLOAT *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetFloat(3);
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<bool>::TypeID: {
|
||||
bool * val = (bool *)data; // Address
|
||||
if (val) {
|
||||
*val = sa.GetBool(3) ? true : false;
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case VAR_TYPE_INSTANCE: {
|
||||
HSQUIRRELVM v = sa.GetVMPtr();
|
||||
SQUserPointer src = sa.GetInstanceUp(3,(SQUserPointer)vr->varType); // Effectively performs: ClassType<>::type() == ClassType<>().
|
||||
if (!src) {
|
||||
throw SquirrelError(_SC("INSTANCE type assignment mismatch"));
|
||||
}
|
||||
vr->varType->vgetCopyFunc()(data,src);
|
||||
return 0;
|
||||
}
|
||||
case TypeInfo<SQUserPointer>::TypeID: {
|
||||
const SQChar * el = sa.GetString(2);
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("setVar(): Cannot write to an SQUserPointer: %s"),el);
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // case
|
||||
case TypeInfo<ScriptStringVarBase>::TypeID: {
|
||||
ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
|
||||
if (val) {
|
||||
const SQChar * strVal = sa.GetString(3);
|
||||
if (strVal) {
|
||||
*val = strVal;
|
||||
return sa.Return(val->s);
|
||||
} // if
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
case TypeInfo<std::string>::TypeID: {
|
||||
std::string *val = (std::string*)data; // Address
|
||||
if (val) {
|
||||
const SQChar *strVal = sa.GetString(3);
|
||||
if (strVal) {
|
||||
*val = strVal;
|
||||
return sa.Return(val->c_str());
|
||||
} // if
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
#endif
|
||||
} // switch
|
||||
return SQ_ERROR;
|
||||
} // setVar
|
||||
|
||||
static int getVar(StackHandler & sa,VarRef * vr,void * data) {
|
||||
switch (vr->m_type) {
|
||||
case TypeInfo<INT>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
if (data) {
|
||||
INT v;
|
||||
// Support for different int sizes
|
||||
switch( vr->m_size ){
|
||||
case 1: v = *(char*)data; break;
|
||||
case 2: v = *(short*)data; break;
|
||||
#ifdef _SQ64
|
||||
case 4: v = *(int*)data; break;
|
||||
#endif
|
||||
default: v = *(INT*)data;
|
||||
}
|
||||
return sa.Return(v);
|
||||
} // if
|
||||
} else {
|
||||
INT * val = (INT *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<unsigned>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
unsigned * val = (unsigned *)data; // Address
|
||||
if (val){
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
}
|
||||
} else {
|
||||
unsigned * val = (unsigned *)&data; // Constant value
|
||||
return sa.Return(static_cast<INT>(*val));
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<FLOAT>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
FLOAT * val = (FLOAT *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
} else {
|
||||
FLOAT * val = (FLOAT *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<bool>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
bool * val = (bool *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
} else {
|
||||
bool * val = (bool *)&data; // Constant value
|
||||
return sa.Return(*val);
|
||||
} // if
|
||||
break;
|
||||
} // case
|
||||
case VAR_TYPE_INSTANCE:
|
||||
if (!CreateNativeClassInstance(sa.GetVMPtr(),vr->varType->GetTypeName(),data,0)) { // data = address. Allocates memory.
|
||||
SCSNPRINTF(g_msg_throw.s,sizeof(g_msg_throw),_SC("getVar(): Could not create instance: %s"),vr->varType->GetTypeName());
|
||||
throw SquirrelError(g_msg_throw.s);
|
||||
} // if
|
||||
return 1;
|
||||
case TypeInfo<SQUserPointer>::TypeID:
|
||||
return sa.Return(data); // The address of member variable, not the variable itself.
|
||||
case TypeInfo<ScriptStringVarBase>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
ScriptStringVarBase * val = (ScriptStringVarBase *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(val->s);
|
||||
} // if
|
||||
} else {
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'ScriptStringVarBase' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
case TypeInfo<const SQChar *>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
if( vr->m_access==VAR_ACCESS_READ_WRITE )
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'const SQChar *' without VAR_ACCESS_CONSTANT"));
|
||||
// It is OK to read from a SQChar* if requested
|
||||
return sa.Return(*(const SQChar **)data); // Address
|
||||
} else {
|
||||
return sa.Return((const SQChar *)data); // Address
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
#ifdef SQPLUS_SUPPORT_STD_STRING
|
||||
case TypeInfo<std::string>::TypeID: {
|
||||
if (!(vr->m_access & VAR_ACCESS_CONSTANT)) {
|
||||
std::string *val = (std::string *)data; // Address
|
||||
if (val) {
|
||||
return sa.Return(val->c_str());
|
||||
}
|
||||
} else {
|
||||
throw SquirrelError(_SC("getVar(): Invalid type+access: 'std::string' with VAR_ACCESS_CONSTANT (use VAR_ACCESS_READ_ONLY instead)"));
|
||||
}
|
||||
break;
|
||||
} // case
|
||||
#endif
|
||||
} // switch
|
||||
return SQ_ERROR;
|
||||
} // getVar
|
||||
|
||||
// === Global Vars ===
|
||||
|
||||
int setVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_TABLE) {
|
||||
VarRefPtr vr;
|
||||
int res = getVarInfo(sa,vr);
|
||||
if (res != SQ_OK) return res;
|
||||
return setVar(sa,vr,vr->offsetOrAddrOrConst);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // setVarFunc
|
||||
|
||||
int getVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_TABLE) {
|
||||
VarRefPtr vr;
|
||||
int res = getVarInfo(sa,vr);
|
||||
if (res != SQ_OK) return res;
|
||||
return getVar(sa,vr,vr->offsetOrAddrOrConst);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // getVarFunc
|
||||
|
||||
// === Instance Vars ===
|
||||
|
||||
int setInstanceVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_INSTANCE) {
|
||||
VarRefPtr vr;
|
||||
void * data;
|
||||
int res = getInstanceVarInfo(sa,vr,data);
|
||||
if (res != SQ_OK) return res;
|
||||
return setVar(sa,vr,data);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // setInstanceVarFunc
|
||||
|
||||
int getInstanceVarFunc(HSQUIRRELVM v) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
StackHandler sa(v);
|
||||
if (sa.GetType(1) == OT_INSTANCE) {
|
||||
VarRefPtr vr;
|
||||
void * data;
|
||||
int res = getInstanceVarInfo(sa,vr,data);
|
||||
if (res != SQ_OK) return res;
|
||||
return getVar(sa,vr,data);
|
||||
} // if
|
||||
return SQ_ERROR;
|
||||
} // getInstanceVarFunc
|
||||
|
||||
// === Classes ===
|
||||
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelObject & newClass,SQUserPointer classType,const SQChar * name,const SQChar * baseName) {
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,name,-1);
|
||||
if (baseName) {
|
||||
sq_pushstring(v,baseName,-1);
|
||||
if (SQ_FAILED(sq_get(v,-3))) { // Make sure the base exists if specified by baseName.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
} // if
|
||||
if (SQ_FAILED(sq_newclass(v,baseName ? 1 : 0))) { // Will inherit from base class on stack from sq_get() above.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
newClass.AttachToStackObject(-1);
|
||||
sq_settypetag(v,-1,classType);
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return TRUE;
|
||||
} // CreateClass
|
||||
|
||||
SquirrelObject RegisterClassType(HSQUIRRELVM v,const SQChar * scriptClassName,SQUserPointer classType,SQFUNCTION constructor) {
|
||||
SquirrelVM::Init(v); // For handling multi-VM setting right
|
||||
int top = sq_gettop(v);
|
||||
SquirrelObject newClass;
|
||||
if (CreateClass(v,newClass,classType,scriptClassName)) {
|
||||
SquirrelVM::CreateFunction(newClass,constructor,_SC("constructor"));
|
||||
} // if
|
||||
sq_settop(v,top);
|
||||
return newClass;
|
||||
} // RegisterClassType
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// GCC sometimes has problems with finding inline functions at link time
|
||||
// (that also have a template definition). To solve the problem,
|
||||
// non-inlines goes here.
|
||||
#ifdef GCC_INLINE_WORKAROUND
|
||||
# include "SqPlusFunctionCallImpl.h"
|
||||
#endif // GCC_INLINE_WORKAROUND
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace SqPlus
|
||||
|
@ -1,337 +1,337 @@
|
||||
|
||||
// This file is included multiple times, with varying options - No header guard.
|
||||
|
||||
// Include this file to generate Call templates with or without these options:
|
||||
// - SQPLUS_APPLY_CONST - const qualifier after functions signature (const func / member func)
|
||||
// - SQPLUS_APPLY_CDECL - qualifier before class name (MSVC specific calling convention)
|
||||
|
||||
#undef CONST_QUAL
|
||||
#undef CALL_QUAL
|
||||
|
||||
#ifdef SQPLUS_APPLY_CONST
|
||||
#define CONST_QUAL const
|
||||
#else
|
||||
#define CONST_QUAL
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_APPLY_CDECL
|
||||
#define CALL_QUAL __cdecl
|
||||
#else
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_RET0
|
||||
|
||||
// Include this file again, with __cdecl also (Visual C++ specific)
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
template <typename Callee>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)() CONST_QUAL,HSQUIRRELVM v,int /*index*/) {
|
||||
RT ret = (callee.*func)();
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename Callee,typename P1>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
sq_argassert(7,index + 6);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5),
|
||||
Get(TypeWrapper<P7>(),v,index + 6)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
#undef SQPLUS_CALL_MFUNC_RET0
|
||||
#endif // SQPLUS_CALL_MFUNC_RET0
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_NORET
|
||||
|
||||
// Include this very same thing with __cdecl also
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
// === Member function calls ===
|
||||
|
||||
template<typename Callee>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)() CONST_QUAL, HSQUIRRELVM,int /*index*/) {
|
||||
(callee.*func)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
sq_argassert(7,index + 6);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5),
|
||||
Get(TypeWrapper<P7>(),v,index + 6)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
#undef SQPLUS_CALL_MFUNC_NORET
|
||||
#endif // SQPLUS_CALL_MFUNC_NORET
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_RET1
|
||||
|
||||
// Include this very same thing with __cdecl also
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
template<typename Callee,typename RT>
|
||||
int Call(Callee & callee, RT (CALL_QUAL Callee::*func)() CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
#undef SQPLUS_CALL_MFUNC_RET1
|
||||
#endif // SQPLUS_CALL_MFUNC_RET1
|
||||
|
||||
// We will be reusing these symbols later
|
||||
#undef SQPLUS_APPLY_CDECL
|
||||
#undef SQPLUS_APPLY_CONST
|
||||
|
||||
// This file is included multiple times, with varying options - No header guard.
|
||||
|
||||
// Include this file to generate Call templates with or without these options:
|
||||
// - SQPLUS_APPLY_CONST - const qualifier after functions signature (const func / member func)
|
||||
// - SQPLUS_APPLY_CDECL - qualifier before class name (MSVC specific calling convention)
|
||||
|
||||
#undef CONST_QUAL
|
||||
#undef CALL_QUAL
|
||||
|
||||
#ifdef SQPLUS_APPLY_CONST
|
||||
#define CONST_QUAL const
|
||||
#else
|
||||
#define CONST_QUAL
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_APPLY_CDECL
|
||||
#define CALL_QUAL __cdecl
|
||||
#else
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_RET0
|
||||
|
||||
// Include this file again, with __cdecl also (Visual C++ specific)
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
template <typename Callee>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)() CONST_QUAL,HSQUIRRELVM v,int /*index*/) {
|
||||
RT ret = (callee.*func)();
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <typename Callee,typename P1>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
static int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL,HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
sq_argassert(7,index + 6);
|
||||
RT ret = (callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5),
|
||||
Get(TypeWrapper<P7>(),v,index + 6)
|
||||
);
|
||||
Push(v,ret);
|
||||
return 1;
|
||||
}
|
||||
#undef SQPLUS_CALL_MFUNC_RET0
|
||||
#endif // SQPLUS_CALL_MFUNC_RET0
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_NORET
|
||||
|
||||
// Include this very same thing with __cdecl also
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
// === Member function calls ===
|
||||
|
||||
template<typename Callee>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)() CONST_QUAL, HSQUIRRELVM,int /*index*/) {
|
||||
(callee.*func)();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<typename Callee,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
static int Call(Callee & callee,void (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
sq_argassert(1,index + 0);
|
||||
sq_argassert(2,index + 1);
|
||||
sq_argassert(3,index + 2);
|
||||
sq_argassert(4,index + 3);
|
||||
sq_argassert(5,index + 4);
|
||||
sq_argassert(6,index + 5);
|
||||
sq_argassert(7,index + 6);
|
||||
(callee.*func)(
|
||||
Get(TypeWrapper<P1>(),v,index + 0),
|
||||
Get(TypeWrapper<P2>(),v,index + 1),
|
||||
Get(TypeWrapper<P3>(),v,index + 2),
|
||||
Get(TypeWrapper<P4>(),v,index + 3),
|
||||
Get(TypeWrapper<P5>(),v,index + 4),
|
||||
Get(TypeWrapper<P6>(),v,index + 5),
|
||||
Get(TypeWrapper<P7>(),v,index + 6)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
#undef SQPLUS_CALL_MFUNC_NORET
|
||||
#endif // SQPLUS_CALL_MFUNC_NORET
|
||||
|
||||
|
||||
#ifdef SQPLUS_CALL_MFUNC_RET1
|
||||
|
||||
// Include this very same thing with __cdecl also
|
||||
#if defined(SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS) && !defined(SQPLUS_APPLY_CDECL)
|
||||
#define SQPLUS_APPLY_CDECL
|
||||
#include "SqPlusCallTemplates.h"
|
||||
#undef CALL_QUAL
|
||||
#define CALL_QUAL
|
||||
#endif
|
||||
|
||||
template<typename Callee,typename RT>
|
||||
int Call(Callee & callee, RT (CALL_QUAL Callee::*func)() CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
template<typename Callee,typename RT,typename P1,typename P2,typename P3,typename P4,typename P5,typename P6,typename P7>
|
||||
int Call(Callee & callee,RT (CALL_QUAL Callee::*func)(P1,P2,P3,P4,P5,P6,P7) CONST_QUAL, HSQUIRRELVM v,int index) {
|
||||
return ReturnSpecialization<RT>::Call(callee,func,v,index);
|
||||
}
|
||||
|
||||
#undef SQPLUS_CALL_MFUNC_RET1
|
||||
#endif // SQPLUS_CALL_MFUNC_RET1
|
||||
|
||||
// We will be reusing these symbols later
|
||||
#undef SQPLUS_APPLY_CDECL
|
||||
#undef SQPLUS_APPLY_CONST
|
@ -1,74 +1,74 @@
|
||||
// SqPlusConst.h
|
||||
// SqPlus constant type and constant member function support created by Simon Michelmore.
|
||||
// Modular integration 11/14/05 jcs.
|
||||
|
||||
#ifdef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
|
||||
#undef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
|
||||
|
||||
// Kamaitati's NULL_INSTANCE support. 5/28/06 jcs
|
||||
|
||||
#ifdef SQPLUS_SUPPORT_NULL_INSTANCES
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
|
||||
inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); }
|
||||
|
||||
// Ordinary case
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE * value) { \
|
||||
if (!value) sq_pushnull(v); \
|
||||
else if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) \
|
||||
throw SquirrelError(_SC("Push(): could not create INSTANCE (check registration name)")); } \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(v,GetTypeName(value),value)) throw SquirrelError(_SC("Push(): could not create INSTANCE copy (check registration name)")); } \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
// Case for custom Push implementation (covariant return type)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CUSTOM_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
template<> void Push(HSQUIRRELVM v,const TYPE * value); \
|
||||
template<> void Push(HSQUIRRELVM v,const TYPE & value); \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE * value) { if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) throw SquirrelError(_SC("Push(): could not create INSTANCE (check registration name)")); } \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(v,GetTypeName(value),value)) throw SquirrelError(_SC("Push(): could not create INSTANCE copy (check registration name)")); } \
|
||||
template<> inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
|
||||
template<> inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
#endif
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,TYPE)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME)
|
||||
#define DECLARE_INSTANCE_TYPE_CUSTOM(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,TYPE)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CUSTOM(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,NAME)
|
||||
#endif
|
||||
|
||||
#define SQPLUS_APPLY_CONST
|
||||
#include "SqPlusCallTemplates.h"
|
||||
|
||||
|
||||
#ifdef SQ_REG_CONST_STATIC_VAR
|
||||
#undef SQ_REG_CONST_STATIC_VAR
|
||||
template<typename VarType>
|
||||
SQClassDefBase & staticVar(const VarType * pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_ONLY) {
|
||||
struct CV {
|
||||
const VarType * var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,VarAccessType(access|VAR_ACCESS_STATIC));
|
||||
return *this;
|
||||
} // staticVar
|
||||
#endif
|
||||
|
||||
// SqPlusConst.h
|
||||
// SqPlusConst.h
|
||||
// SqPlus constant type and constant member function support created by Simon Michelmore.
|
||||
// Modular integration 11/14/05 jcs.
|
||||
|
||||
#ifdef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
|
||||
#undef SQPLUS_DECLARE_INSTANCE_TYPE_CONST
|
||||
|
||||
// Kamaitati's NULL_INSTANCE support. 5/28/06 jcs
|
||||
|
||||
#ifdef SQPLUS_SUPPORT_NULL_INSTANCES
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
|
||||
inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); }
|
||||
|
||||
// Ordinary case
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE * value) { \
|
||||
if (!value) sq_pushnull(v); \
|
||||
else if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) \
|
||||
throw SquirrelError(_SC("Push(): could not create INSTANCE (check registration name)")); } \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(v,GetTypeName(value),value)) throw SquirrelError(_SC("Push(): could not create INSTANCE copy (check registration name)")); } \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
// Case for custom Push implementation (covariant return type)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CUSTOM_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
DECLARE_INSTANCE_TYPE_NAME_CONST_BASE(TYPE,NAME) \
|
||||
template<> void Push(HSQUIRRELVM v,const TYPE * value); \
|
||||
template<> void Push(HSQUIRRELVM v,const TYPE & value); \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME) \
|
||||
DECLARE_INSTANCE_TYPE_NAME_(TYPE,NAME) \
|
||||
namespace SqPlus { \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE * value) { if (!CreateNativeClassInstance(v,GetTypeName(*value),(TYPE*)value,0)) throw SquirrelError(_SC("Push(): could not create INSTANCE (check registration name)")); } \
|
||||
template<> inline void Push(HSQUIRRELVM v,const TYPE & value) { if (!CreateCopyInstance(v,GetTypeName(value),value)) throw SquirrelError(_SC("Push(): could not create INSTANCE copy (check registration name)")); } \
|
||||
template<> inline bool Match(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return GetInstance<TYPE,false>(v,idx) != NULL; } \
|
||||
template<> inline const TYPE & Get(TypeWrapper<const TYPE &>,HSQUIRRELVM v,int idx) { return *GetInstance<TYPE,true>(v,idx); } \
|
||||
} // nameSpace SqPlus
|
||||
|
||||
#endif
|
||||
|
||||
#define DECLARE_INSTANCE_TYPE(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,TYPE)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST(TYPE,NAME)
|
||||
#define DECLARE_INSTANCE_TYPE_CUSTOM(TYPE) DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,TYPE)
|
||||
#define DECLARE_INSTANCE_TYPE_NAME_CUSTOM(TYPE,NAME) DECLARE_INSTANCE_TYPE_NAME_CONST_CUSTOM(TYPE,NAME)
|
||||
#endif
|
||||
|
||||
#define SQPLUS_APPLY_CONST
|
||||
#include "SqPlusCallTemplates.h"
|
||||
|
||||
|
||||
#ifdef SQ_REG_CONST_STATIC_VAR
|
||||
#undef SQ_REG_CONST_STATIC_VAR
|
||||
template<typename VarType>
|
||||
SQClassDefBase & staticVar(const VarType * pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_ONLY) {
|
||||
struct CV {
|
||||
const VarType * var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,VarAccessType(access|VAR_ACCESS_STATIC));
|
||||
return *this;
|
||||
} // staticVar
|
||||
#endif
|
||||
|
||||
// SqPlusConst.h
|
@ -1,114 +1,114 @@
|
||||
#ifndef _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
#define _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
|
||||
#ifdef GCC_INLINE_WORKAROUND
|
||||
# define SQINLINE
|
||||
#else
|
||||
# define SQINLINE inline
|
||||
#endif
|
||||
|
||||
SQINLINE void Push(HSQUIRRELVM v,char value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned char value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,short value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned short value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,int value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned int value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,long value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned long value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,double value) { sq_pushfloat(v,(FLOAT)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,float value) { sq_pushfloat(v,(FLOAT)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SQChar * value) { sq_pushstring(v,value,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQChar * value) { sq_pushstring(v,value,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SquirrelNull &) { sq_pushnull(v); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQFUNCTION value) { sq_pushuserpointer(v,(void*)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQAnythingPtr value) { sq_pushuserpointer(v,(void*)value); } // Cast to SQAnythingPtr instead of void * if USE_ARGUMENT_DEPENDANT_OVERLOADS can't be used by your compiler.
|
||||
SQINLINE void Push(HSQUIRRELVM v,SquirrelObject & so) { sq_pushobject(v,so.GetObjectHandle()); }
|
||||
|
||||
#ifdef USE_ARGUMENT_DEPENDANT_OVERLOADS
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4675) // Disable warning: "resolved overload was found by argument-dependent lookup" when class/struct pointers are used as function arguments.
|
||||
#endif
|
||||
// === BEGIN Argument Dependent Overloads ===
|
||||
SQINLINE void Push(HSQUIRRELVM v,bool value) { sq_pushbool(v,value); } // Pass bool as int if USE_ARGUMENT_DEPENDANT_OVERLOADS can't be used by your compiler.
|
||||
SQINLINE void Push(HSQUIRRELVM v,const void * value) { sq_pushuserpointer(v,(void*)value); } // Pass SQAnythingPtr instead of void * " "
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SQUserPointer & value) { sq_pushuserpointer(v,(void*)value); }
|
||||
// === END Argument Dependent Overloads ===
|
||||
#endif
|
||||
|
||||
#define SQPLUS_CHECK_GET(res) if (!SQ_SUCCEEDED(res)) throw SquirrelError(_SC("sq_get*() failed (type error)"))
|
||||
|
||||
//SQINLINE bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_BOOL; }
|
||||
SQINLINE bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { return true; } // All types can be cast to bool
|
||||
SQINLINE bool Match(TypeWrapper<char>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned char>,HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<int>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<long>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<float>,HSQUIRRELVM v,int idx) { int type = sq_gettype(v,idx); return type == OT_FLOAT; }
|
||||
SQINLINE bool Match(TypeWrapper<double>,HSQUIRRELVM v,int idx) { int type = sq_gettype(v,idx); return type == OT_FLOAT; }
|
||||
SQINLINE bool Match(TypeWrapper<const SQChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<SQChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<HSQUIRRELVM>,HSQUIRRELVM v,int idx) { return true; } // See Get() for HSQUIRRELVM below (v is always present).
|
||||
SQINLINE bool Match(TypeWrapper<void*>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_USERPOINTER; }
|
||||
SQINLINE bool Match(TypeWrapper<SquirrelObject>,HSQUIRRELVM v,int idx) { return true; } // See sq_getstackobj(): always returns true.
|
||||
|
||||
SQINLINE void Get(TypeWrapper<void>,HSQUIRRELVM v,int) {}
|
||||
//SQINLINE bool Get(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { SQBool b; SQPLUS_CHECK_GET(sq_getbool(v,idx,&b)); return b != 0; }
|
||||
SQINLINE char Get(TypeWrapper<char>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<char>(i); }
|
||||
SQINLINE unsigned char Get(TypeWrapper<unsigned char>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned char>(i); }
|
||||
SQINLINE short Get(TypeWrapper<short>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<short>(i); }
|
||||
SQINLINE unsigned short Get(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned short>(i); }
|
||||
SQINLINE int Get(TypeWrapper<int>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return i; }
|
||||
SQINLINE unsigned int Get(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned int>(i); }
|
||||
SQINLINE long Get(TypeWrapper<long>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<long>(i); }
|
||||
SQINLINE unsigned long Get(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned long>(i); }
|
||||
SQINLINE float Get(TypeWrapper<float>,HSQUIRRELVM v,int idx) { FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return f; }
|
||||
SQINLINE double Get(TypeWrapper<double>,HSQUIRRELVM v,int idx) { FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return static_cast<double>(f); }
|
||||
SQINLINE const SQChar * Get(TypeWrapper<const SQChar *>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return s; }
|
||||
SQINLINE SquirrelNull Get(TypeWrapper<SquirrelNull>,HSQUIRRELVM v,int idx) { (void)v, (void)idx; return SquirrelNull(); }
|
||||
SQINLINE void * Get(TypeWrapper<void *>,HSQUIRRELVM v,int idx) { SQUserPointer p; SQPLUS_CHECK_GET(sq_getuserpointer(v,idx,&p)); return p; }
|
||||
SQINLINE HSQUIRRELVM Get(TypeWrapper<HSQUIRRELVM>,HSQUIRRELVM v,int /*idx*/) { sq_poptop(v); return v; } // sq_poptop(v): remove UserData from stack so GetParamCount() matches normal behavior.
|
||||
SQINLINE SquirrelObject Get(TypeWrapper<SquirrelObject>,HSQUIRRELVM v,int idx) { HSQOBJECT o; SQPLUS_CHECK_GET(sq_getstackobj(v,idx,&o)); return SquirrelObject(o); }
|
||||
|
||||
SQINLINE bool Get(TypeWrapper<bool>,HSQUIRRELVM v,int idx){
|
||||
switch( sq_gettype(v,idx) ){
|
||||
case OT_NULL:{ return false; }
|
||||
case OT_BOOL:{ SQBool b; SQPLUS_CHECK_GET(sq_getbool(v,idx,&b)); return b != 0; }
|
||||
case OT_INTEGER:{ INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return i != 0; }
|
||||
case OT_FLOAT:{ FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return f != (FLOAT)0.0; }
|
||||
default: return true; } }
|
||||
|
||||
#ifdef SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
SQINLINE void Push(HSQUIRRELVM v, const SQOtherChar *value){ SQDefCharBuf cb(value); sq_pushstring(v,(const SQChar*)cb,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v, SQOtherChar *value){ SQDefCharBuf cb(value); sq_pushstring(v,(const SQChar*)cb,-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<SQOtherChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
/*SQINLINE SQOtherChar* Get(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) {
|
||||
const SQChar *s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s));
|
||||
static SQOthCharBuf ocb[SQPLUS_AUTOCONVERT_MAX_INSTANCES]; static int st_buf_cnt;
|
||||
return ocb[st_buf_cnt++%SQPLUS_AUTOCONVERT_MAX_INSTANCES].Set(s); }*/
|
||||
SQINLINE SQOthCharBuf Get(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return SQOthCharBuf(s); }
|
||||
#endif // SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
SQINLINE void Push(HSQUIRRELVM v,const std::string& value) { sq_pushstring(v,value.c_str(),-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const std::string&>, HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE std::string Get(TypeWrapper<const std::string&>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return std::string(s); }
|
||||
#endif // defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
|
||||
// Added jflanglois suggestion, 8/20/06. jcs
|
||||
#ifdef SQPLUS_SUPPORT_SQ_STD_STRING
|
||||
typedef std::basic_string<SQChar> sq_std_string;
|
||||
SQINLINE void Push(HSQUIRRELVM v,const sq_std_string & value) { sq_pushstring(v,value.c_str(),-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const sq_std_string &>, HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE sq_std_string Get(TypeWrapper<const sq_std_string &>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return sq_std_string(s); }
|
||||
#endif
|
||||
|
||||
// Specialization to support void return type.
|
||||
SQINLINE void GetRet(TypeWrapper<void>,HSQUIRRELVM v,int idx) { sq_pop(v,2); }
|
||||
|
||||
#endif // _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
|
||||
#ifndef _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
#define _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
|
||||
#ifdef GCC_INLINE_WORKAROUND
|
||||
# define SQINLINE
|
||||
#else
|
||||
# define SQINLINE inline
|
||||
#endif
|
||||
|
||||
SQINLINE void Push(HSQUIRRELVM v,char value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned char value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,short value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned short value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,int value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned int value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,long value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,unsigned long value) { sq_pushinteger(v,value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,double value) { sq_pushfloat(v,(FLOAT)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,float value) { sq_pushfloat(v,(FLOAT)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SQChar * value) { sq_pushstring(v,value,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQChar * value) { sq_pushstring(v,value,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SquirrelNull &) { sq_pushnull(v); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQFUNCTION value) { sq_pushuserpointer(v,(void*)value); }
|
||||
SQINLINE void Push(HSQUIRRELVM v,SQAnythingPtr value) { sq_pushuserpointer(v,(void*)value); } // Cast to SQAnythingPtr instead of void * if USE_ARGUMENT_DEPENDANT_OVERLOADS can't be used by your compiler.
|
||||
SQINLINE void Push(HSQUIRRELVM v,SquirrelObject & so) { sq_pushobject(v,so.GetObjectHandle()); }
|
||||
|
||||
#ifdef USE_ARGUMENT_DEPENDANT_OVERLOADS
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (disable:4675) // Disable warning: "resolved overload was found by argument-dependent lookup" when class/struct pointers are used as function arguments.
|
||||
#endif
|
||||
// === BEGIN Argument Dependent Overloads ===
|
||||
SQINLINE void Push(HSQUIRRELVM v,bool value) { sq_pushbool(v,value); } // Pass bool as int if USE_ARGUMENT_DEPENDANT_OVERLOADS can't be used by your compiler.
|
||||
SQINLINE void Push(HSQUIRRELVM v,const void * value) { sq_pushuserpointer(v,(void*)value); } // Pass SQAnythingPtr instead of void * " "
|
||||
SQINLINE void Push(HSQUIRRELVM v,const SQUserPointer & value) { sq_pushuserpointer(v,(void*)value); }
|
||||
// === END Argument Dependent Overloads ===
|
||||
#endif
|
||||
|
||||
#define SQPLUS_CHECK_GET(res) if (!SQ_SUCCEEDED(res)) throw SquirrelError(_SC("sq_get*() failed (type error)"))
|
||||
|
||||
//SQINLINE bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_BOOL; }
|
||||
SQINLINE bool Match(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { return true; } // All types can be cast to bool
|
||||
SQINLINE bool Match(TypeWrapper<char>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned char>,HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<int>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<long>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_INTEGER; }
|
||||
SQINLINE bool Match(TypeWrapper<float>,HSQUIRRELVM v,int idx) { int type = sq_gettype(v,idx); return type == OT_FLOAT; }
|
||||
SQINLINE bool Match(TypeWrapper<double>,HSQUIRRELVM v,int idx) { int type = sq_gettype(v,idx); return type == OT_FLOAT; }
|
||||
SQINLINE bool Match(TypeWrapper<const SQChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<SQChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<HSQUIRRELVM>,HSQUIRRELVM v,int idx) { return true; } // See Get() for HSQUIRRELVM below (v is always present).
|
||||
SQINLINE bool Match(TypeWrapper<void*>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_USERPOINTER; }
|
||||
SQINLINE bool Match(TypeWrapper<SquirrelObject>,HSQUIRRELVM v,int idx) { return true; } // See sq_getstackobj(): always returns true.
|
||||
|
||||
SQINLINE void Get(TypeWrapper<void>,HSQUIRRELVM v,int) {}
|
||||
//SQINLINE bool Get(TypeWrapper<bool>,HSQUIRRELVM v,int idx) { SQBool b; SQPLUS_CHECK_GET(sq_getbool(v,idx,&b)); return b != 0; }
|
||||
SQINLINE char Get(TypeWrapper<char>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<char>(i); }
|
||||
SQINLINE unsigned char Get(TypeWrapper<unsigned char>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned char>(i); }
|
||||
SQINLINE short Get(TypeWrapper<short>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<short>(i); }
|
||||
SQINLINE unsigned short Get(TypeWrapper<unsigned short>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned short>(i); }
|
||||
SQINLINE int Get(TypeWrapper<int>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return i; }
|
||||
SQINLINE unsigned int Get(TypeWrapper<unsigned int>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned int>(i); }
|
||||
SQINLINE long Get(TypeWrapper<long>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<long>(i); }
|
||||
SQINLINE unsigned long Get(TypeWrapper<unsigned long>,HSQUIRRELVM v,int idx) { INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return static_cast<unsigned long>(i); }
|
||||
SQINLINE float Get(TypeWrapper<float>,HSQUIRRELVM v,int idx) { FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return f; }
|
||||
SQINLINE double Get(TypeWrapper<double>,HSQUIRRELVM v,int idx) { FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return static_cast<double>(f); }
|
||||
SQINLINE const SQChar * Get(TypeWrapper<const SQChar *>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return s; }
|
||||
SQINLINE SquirrelNull Get(TypeWrapper<SquirrelNull>,HSQUIRRELVM v,int idx) { (void)v, (void)idx; return SquirrelNull(); }
|
||||
SQINLINE void * Get(TypeWrapper<void *>,HSQUIRRELVM v,int idx) { SQUserPointer p; SQPLUS_CHECK_GET(sq_getuserpointer(v,idx,&p)); return p; }
|
||||
SQINLINE HSQUIRRELVM Get(TypeWrapper<HSQUIRRELVM>,HSQUIRRELVM v,int /*idx*/) { sq_poptop(v); return v; } // sq_poptop(v): remove UserData from stack so GetParamCount() matches normal behavior.
|
||||
SQINLINE SquirrelObject Get(TypeWrapper<SquirrelObject>,HSQUIRRELVM v,int idx) { HSQOBJECT o; SQPLUS_CHECK_GET(sq_getstackobj(v,idx,&o)); return SquirrelObject(o); }
|
||||
|
||||
SQINLINE bool Get(TypeWrapper<bool>,HSQUIRRELVM v,int idx){
|
||||
switch( sq_gettype(v,idx) ){
|
||||
case OT_NULL:{ return false; }
|
||||
case OT_BOOL:{ SQBool b; SQPLUS_CHECK_GET(sq_getbool(v,idx,&b)); return b != 0; }
|
||||
case OT_INTEGER:{ INT i; SQPLUS_CHECK_GET(sq_getinteger(v,idx,&i)); return i != 0; }
|
||||
case OT_FLOAT:{ FLOAT f; SQPLUS_CHECK_GET(sq_getfloat(v,idx,&f)); return f != (FLOAT)0.0; }
|
||||
default: return true; } }
|
||||
|
||||
#ifdef SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
SQINLINE void Push(HSQUIRRELVM v, const SQOtherChar *value){ SQDefCharBuf cb(value); sq_pushstring(v,(const SQChar*)cb,-1); }
|
||||
SQINLINE void Push(HSQUIRRELVM v, SQOtherChar *value){ SQDefCharBuf cb(value); sq_pushstring(v,(const SQChar*)cb,-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE bool Match(TypeWrapper<SQOtherChar *>,HSQUIRRELVM v,int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
/*SQINLINE SQOtherChar* Get(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) {
|
||||
const SQChar *s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s));
|
||||
static SQOthCharBuf ocb[SQPLUS_AUTOCONVERT_MAX_INSTANCES]; static int st_buf_cnt;
|
||||
return ocb[st_buf_cnt++%SQPLUS_AUTOCONVERT_MAX_INSTANCES].Set(s); }*/
|
||||
SQINLINE SQOthCharBuf Get(TypeWrapper<const SQOtherChar *>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return SQOthCharBuf(s); }
|
||||
#endif // SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
SQINLINE void Push(HSQUIRRELVM v,const std::string& value) { sq_pushstring(v,value.c_str(),-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const std::string&>, HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE std::string Get(TypeWrapper<const std::string&>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return std::string(s); }
|
||||
#endif // defined(SQPLUS_SUPPORT_STD_STRING) && !defined(SQUNICODE)
|
||||
|
||||
// Added jflanglois suggestion, 8/20/06. jcs
|
||||
#ifdef SQPLUS_SUPPORT_SQ_STD_STRING
|
||||
typedef std::basic_string<SQChar> sq_std_string;
|
||||
SQINLINE void Push(HSQUIRRELVM v,const sq_std_string & value) { sq_pushstring(v,value.c_str(),-1); }
|
||||
SQINLINE bool Match(TypeWrapper<const sq_std_string &>, HSQUIRRELVM v, int idx) { return sq_gettype(v,idx) == OT_STRING; }
|
||||
SQINLINE sq_std_string Get(TypeWrapper<const sq_std_string &>,HSQUIRRELVM v,int idx) { const SQChar * s; SQPLUS_CHECK_GET(sq_getstring(v,idx,&s)); return sq_std_string(s); }
|
||||
#endif
|
||||
|
||||
// Specialization to support void return type.
|
||||
SQINLINE void GetRet(TypeWrapper<void>,HSQUIRRELVM v,int idx) { sq_pop(v,2); }
|
||||
|
||||
#endif // _SQPLUS_FUNCTION_CALL_IMPL_H_
|
||||
|
@ -1,61 +1,61 @@
|
||||
|
||||
#include "sqplus.h"
|
||||
#include "SqPlusOCharBuf.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
// Conversion functions, between char* string and wchar_t* strings.
|
||||
|
||||
int ol_strlen(const wchar_t* pwc){ return (int)wcslen(pwc); }
|
||||
int ol_buflen(const wchar_t* pwc){ return (int)wcslen(pwc); }
|
||||
int ol_charlen(const wchar_t* pwc){ return 1; }
|
||||
//int ol_charlen(const wchar_t pwc){ return 1; }
|
||||
int ol_char(const wchar_t* pwc){ return (int)*pwc; }
|
||||
bool ol_writechar(wchar_t*& pwc, int ch){ *pwc=(wchar_t)ch; pwc++; return true; }
|
||||
|
||||
int ol_buflen(const char* pc){ return (int)strlen(pc); }
|
||||
|
||||
#if SQPLUS_USE_LATIN1==1
|
||||
// Convert to 8-bit LATIN1 char set. The only thing to do is convert chars out of range to '?'
|
||||
int ol_strlen(const char* pc){ return (int)strlen(pc); }
|
||||
int ol_charlen(const char* pc){ return 1; }
|
||||
//int ol_charlen(int pc){ return 1; }
|
||||
int ol_char(const char* pc){ return (int)*(unsigned char*)pc; }
|
||||
bool ol_writechar(char*& pc, int ch){ *pc=(char)(ch>255?'?':ch); pc++; return true; }
|
||||
#else
|
||||
#include "SqPlusUtf8.h"
|
||||
// Convert to 8-Bit UTF8 encoding. Some more work here.
|
||||
int ol_strlen(const char* pc){ return sqplus_utf8_strlen(pc); }
|
||||
int ol_charlen(const char* pc){ return sqplus_utf8_len_first(pc); }
|
||||
//int ol_charlen(int ch){ char buf[8]; return sqplus_wchar_to_utf8(buf,ch,8); }
|
||||
int ol_char(const char* pc){ int chr=-1; sqplus_utf8_to_wchar(&chr,pc); return chr; }
|
||||
bool ol_writechar(char*& pc, int ch) {
|
||||
int l=sqplus_wchar_to_utf8(pc,ch,8);
|
||||
if(l>0){
|
||||
pc += l;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from to either Latin1 or UTF8
|
||||
SQDefCharBuf CH2SQ( const char* ps ){
|
||||
return SQDefCharBuf(ps);
|
||||
}
|
||||
SQOthCharBuf SQ2CH( const wchar_t* pws ){
|
||||
return SQOthCharBuf(pws);
|
||||
}
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
SQDefCharBuf WC2SQ( const wchar_t* pws ){
|
||||
return SQDefCharBuf(pws);
|
||||
}
|
||||
SQOthCharBuf SQ2WC( const char* ps ){
|
||||
return SQOthCharBuf(ps);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#include "sqplus.h"
|
||||
#include "SqPlusOCharBuf.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
// Conversion functions, between char* string and wchar_t* strings.
|
||||
|
||||
int ol_strlen(const wchar_t* pwc){ return (int)wcslen(pwc); }
|
||||
int ol_buflen(const wchar_t* pwc){ return (int)wcslen(pwc); }
|
||||
int ol_charlen(const wchar_t* pwc){ return 1; }
|
||||
//int ol_charlen(const wchar_t pwc){ return 1; }
|
||||
int ol_char(const wchar_t* pwc){ return (int)*pwc; }
|
||||
bool ol_writechar(wchar_t*& pwc, int ch){ *pwc=(wchar_t)ch; pwc++; return true; }
|
||||
|
||||
int ol_buflen(const char* pc){ return (int)strlen(pc); }
|
||||
|
||||
#if SQPLUS_USE_LATIN1==1
|
||||
// Convert to 8-bit LATIN1 char set. The only thing to do is convert chars out of range to '?'
|
||||
int ol_strlen(const char* pc){ return (int)strlen(pc); }
|
||||
int ol_charlen(const char* pc){ return 1; }
|
||||
//int ol_charlen(int pc){ return 1; }
|
||||
int ol_char(const char* pc){ return (int)*(unsigned char*)pc; }
|
||||
bool ol_writechar(char*& pc, int ch){ *pc=(char)(ch>255?'?':ch); pc++; return true; }
|
||||
#else
|
||||
#include "SqPlusUtf8.h"
|
||||
// Convert to 8-Bit UTF8 encoding. Some more work here.
|
||||
int ol_strlen(const char* pc){ return sqplus_utf8_strlen(pc); }
|
||||
int ol_charlen(const char* pc){ return sqplus_utf8_len_first(pc); }
|
||||
//int ol_charlen(int ch){ char buf[8]; return sqplus_wchar_to_utf8(buf,ch,8); }
|
||||
int ol_char(const char* pc){ int chr=-1; sqplus_utf8_to_wchar(&chr,pc); return chr; }
|
||||
bool ol_writechar(char*& pc, int ch) {
|
||||
int l=sqplus_wchar_to_utf8(pc,ch,8);
|
||||
if(l>0){
|
||||
pc += l;
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from to either Latin1 or UTF8
|
||||
SQDefCharBuf CH2SQ( const char* ps ){
|
||||
return SQDefCharBuf(ps);
|
||||
}
|
||||
SQOthCharBuf SQ2CH( const wchar_t* pws ){
|
||||
return SQOthCharBuf(pws);
|
||||
}
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
SQDefCharBuf WC2SQ( const wchar_t* pws ){
|
||||
return SQDefCharBuf(pws);
|
||||
}
|
||||
SQOthCharBuf SQ2WC( const char* ps ){
|
||||
return SQOthCharBuf(ps);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,193 +1,193 @@
|
||||
|
||||
#ifndef SQPLUS_OCHARBUF_H
|
||||
#define SQPLUS_OCHARBUF_H
|
||||
|
||||
// Conversion routines between different character encodings, to be used in
|
||||
// Push/Get/Match handlers of SqPlus. It enables using both of char* and
|
||||
// wchar_t* as function arguments.
|
||||
//
|
||||
// When converting from wchar_t to char, the choice is between using a Latin1
|
||||
// or a UTF8 representation in 8-bit mode. This is probably most useful if
|
||||
// Squirrel is compiled in ANSI mode and the app uses some wchar_t strings
|
||||
// (UNICODE mode on Win32).
|
||||
//
|
||||
|
||||
// A char is either
|
||||
// - A Latin1 character (first code page, coincides with Unicode points 0..255)
|
||||
// - Part of an UTF8 character
|
||||
//
|
||||
// Note: SQUTF8 requires Squirrel sources that have been patched for UTF8 strings
|
||||
// internally (when converting function arguments).
|
||||
|
||||
#ifndef SQUTF8
|
||||
// Default to Latin1 conversion
|
||||
//#undef SQPLUS_USE_LATIN1
|
||||
#ifndef SQPLUS_USE_LATIN1
|
||||
#define SQPLUS_USE_LATIN1 1
|
||||
#endif
|
||||
#else
|
||||
// Using Squirrel with internal UTF8 string encoding
|
||||
//#undef SQPLUS_USE_LATIN1
|
||||
#ifndef SQPLUS_USE_LATIN1
|
||||
#define SQPLUS_USE_LATIN1 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// The various ol_... functions sets up for a conversion scheme
|
||||
// that can be used in both wchar_t => char and char => wchar_t.
|
||||
int ol_strlen(const wchar_t* pwc);
|
||||
int ol_buflen(const wchar_t* pwc);
|
||||
int ol_charlen(const wchar_t* pwc);
|
||||
int ol_char(const wchar_t* pwc);
|
||||
bool ol_writechar(wchar_t*& pwc, int ch);
|
||||
|
||||
int ol_strlen(const char* pc);
|
||||
int ol_buflen(const char* pc);
|
||||
int ol_charlen(const char* pc);
|
||||
int ol_char(const char* pc);
|
||||
bool ol_writechar(char*& pc, int ch);
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from either Latin1 or UTF8
|
||||
typedef char SQOtherChar;
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
typedef wchar_t SQOtherChar;
|
||||
#endif
|
||||
|
||||
|
||||
// Buffer to hold a string and release it in destructor.
|
||||
// SQT is input character type
|
||||
// SQOT is the opposite type of SQChar
|
||||
// If 'try_borrow' is set, it will not allocate a new buffer when no
|
||||
// conversion is done, it will just keep the input pointer (beware).
|
||||
template<class SQT, class SQOT, bool use_latin1>
|
||||
struct SQCharBufImpl {
|
||||
|
||||
// Allocate a buffer from string of same type
|
||||
SQCharBufImpl(const SQT *poc=NULL, bool try_borrow=true ) : m_poc(0), m_own(false) {
|
||||
Init( poc, try_borrow );
|
||||
}
|
||||
|
||||
// This does conversion from other char type
|
||||
SQCharBufImpl(const SQOT *ps, bool try_borrow=false ) : m_poc(0), m_own(false) {
|
||||
Init( ps ); // Cannot borrow pointer when doing conversion
|
||||
}
|
||||
|
||||
void Init( const SQT *poc, bool try_borrow ){
|
||||
m_own = !try_borrow;
|
||||
if( try_borrow ){
|
||||
m_poc = (SQT*)poc;
|
||||
}
|
||||
else {
|
||||
int sl = poc ? ol_buflen(poc) : 0;
|
||||
if( poc ){
|
||||
m_poc = poc ? new SQT[sl+1] : NULL;
|
||||
if( m_poc ) memcpy( m_poc, poc, (sl+1)*sizeof(SQT) );
|
||||
}
|
||||
else
|
||||
m_poc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Init( const SQOT *ps ){
|
||||
m_own = true;
|
||||
if( ps ){
|
||||
int sl = ps ? ol_strlen(ps) : 0; // Length of string in characters (not bytes)
|
||||
int scl = 0; // Length of converted string in char/wchar_t count
|
||||
// How much storage needed?
|
||||
if( !use_latin1 && sizeof(SQT)<sizeof(SQOT) ){
|
||||
// Converting wchar_t => UTF8
|
||||
const SQOT *ps1 = ps; // It is wchar_t* here
|
||||
SQT tmp_buf[8];
|
||||
SQT *ptmp;
|
||||
while( *ps1 ){
|
||||
ptmp = tmp_buf;
|
||||
if( ol_writechar(ptmp,*ps1++) )
|
||||
scl += ol_charlen(tmp_buf);
|
||||
else
|
||||
scl++;
|
||||
}
|
||||
}
|
||||
else scl = sl; // Converting to wchar_t or Latin1, keep length
|
||||
|
||||
m_poc = new SQT[scl+1];
|
||||
if( !m_poc ) return;
|
||||
|
||||
// Convert
|
||||
SQT *poc = m_poc;
|
||||
while( *ps ){
|
||||
ol_writechar( poc, ol_char(ps) );
|
||||
ps += ol_charlen(ps);
|
||||
}
|
||||
*poc = 0; // Terminating zero
|
||||
}
|
||||
else
|
||||
m_poc = NULL;
|
||||
}
|
||||
|
||||
~SQCharBufImpl(){ Release(); }
|
||||
|
||||
void Release( ){
|
||||
if(m_poc && m_own )
|
||||
delete [] m_poc;
|
||||
m_poc = NULL;
|
||||
}
|
||||
|
||||
SQT* Set( const SQOT *ps ){
|
||||
Release( );
|
||||
Init( ps );
|
||||
return m_poc;
|
||||
}
|
||||
|
||||
operator SQT*() const { return m_poc; }
|
||||
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQT *ps){
|
||||
Release();
|
||||
Init( ps, false );
|
||||
return *this;
|
||||
}
|
||||
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQOT *ps){
|
||||
Release();
|
||||
Init( ps );
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Move string from other here - Note: Empties the input argument (other)
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQCharBufImpl<SQT,SQOT,use_latin1>& other){
|
||||
Release();
|
||||
m_poc = other.m_poc;
|
||||
m_own = other.m_own;
|
||||
SQT **psqt = (SQT**)&other.m_poc;
|
||||
*psqt = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
SQT *m_poc;
|
||||
bool m_own;
|
||||
};
|
||||
|
||||
typedef SQCharBufImpl<SQOtherChar, SQChar, bool(SQPLUS_USE_LATIN1)> SQOthCharBuf;
|
||||
typedef SQCharBufImpl<SQChar, SQOtherChar, bool(SQPLUS_USE_LATIN1)> SQDefCharBuf;
|
||||
typedef SQCharBufImpl<wchar_t, char, bool(SQPLUS_USE_LATIN1)> SQWCharBuf;
|
||||
typedef SQCharBufImpl<char, wchar_t, bool(SQPLUS_USE_LATIN1)> SQACharBuf;
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from to either Latin1 or UTF8
|
||||
#define WC2SQ(s) s
|
||||
#define SQ2WC(s) s
|
||||
SQDefCharBuf CH2SQ( const char* ps );
|
||||
SQOthCharBuf SQ2CH( const wchar_t* pws );
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
SQDefCharBuf WC2SQ( const wchar_t* pws );
|
||||
SQOthCharBuf SQ2WC( const char* pws );
|
||||
#define CH2SQ(s) s
|
||||
#define SQ2CH(s) s
|
||||
#endif
|
||||
|
||||
#endif // SQPLUS_CHARBUF_H
|
||||
|
||||
|
||||
#ifndef SQPLUS_OCHARBUF_H
|
||||
#define SQPLUS_OCHARBUF_H
|
||||
|
||||
// Conversion routines between different character encodings, to be used in
|
||||
// Push/Get/Match handlers of SqPlus. It enables using both of char* and
|
||||
// wchar_t* as function arguments.
|
||||
//
|
||||
// When converting from wchar_t to char, the choice is between using a Latin1
|
||||
// or a UTF8 representation in 8-bit mode. This is probably most useful if
|
||||
// Squirrel is compiled in ANSI mode and the app uses some wchar_t strings
|
||||
// (UNICODE mode on Win32).
|
||||
//
|
||||
|
||||
// A char is either
|
||||
// - A Latin1 character (first code page, coincides with Unicode points 0..255)
|
||||
// - Part of an UTF8 character
|
||||
//
|
||||
// Note: SQUTF8 requires Squirrel sources that have been patched for UTF8 strings
|
||||
// internally (when converting function arguments).
|
||||
|
||||
#ifndef SQUTF8
|
||||
// Default to Latin1 conversion
|
||||
//#undef SQPLUS_USE_LATIN1
|
||||
#ifndef SQPLUS_USE_LATIN1
|
||||
#define SQPLUS_USE_LATIN1 1
|
||||
#endif
|
||||
#else
|
||||
// Using Squirrel with internal UTF8 string encoding
|
||||
//#undef SQPLUS_USE_LATIN1
|
||||
#ifndef SQPLUS_USE_LATIN1
|
||||
#define SQPLUS_USE_LATIN1 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// The various ol_... functions sets up for a conversion scheme
|
||||
// that can be used in both wchar_t => char and char => wchar_t.
|
||||
int ol_strlen(const wchar_t* pwc);
|
||||
int ol_buflen(const wchar_t* pwc);
|
||||
int ol_charlen(const wchar_t* pwc);
|
||||
int ol_char(const wchar_t* pwc);
|
||||
bool ol_writechar(wchar_t*& pwc, int ch);
|
||||
|
||||
int ol_strlen(const char* pc);
|
||||
int ol_buflen(const char* pc);
|
||||
int ol_charlen(const char* pc);
|
||||
int ol_char(const char* pc);
|
||||
bool ol_writechar(char*& pc, int ch);
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from either Latin1 or UTF8
|
||||
typedef char SQOtherChar;
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
typedef wchar_t SQOtherChar;
|
||||
#endif
|
||||
|
||||
|
||||
// Buffer to hold a string and release it in destructor.
|
||||
// SQT is input character type
|
||||
// SQOT is the opposite type of SQChar
|
||||
// If 'try_borrow' is set, it will not allocate a new buffer when no
|
||||
// conversion is done, it will just keep the input pointer (beware).
|
||||
template<class SQT, class SQOT, bool use_latin1>
|
||||
struct SQCharBufImpl {
|
||||
|
||||
// Allocate a buffer from string of same type
|
||||
SQCharBufImpl(const SQT *poc=NULL, bool try_borrow=true ) : m_poc(0), m_own(false) {
|
||||
Init( poc, try_borrow );
|
||||
}
|
||||
|
||||
// This does conversion from other char type
|
||||
SQCharBufImpl(const SQOT *ps, bool try_borrow=false ) : m_poc(0), m_own(false) {
|
||||
Init( ps ); // Cannot borrow pointer when doing conversion
|
||||
}
|
||||
|
||||
void Init( const SQT *poc, bool try_borrow ){
|
||||
m_own = !try_borrow;
|
||||
if( try_borrow ){
|
||||
m_poc = (SQT*)poc;
|
||||
}
|
||||
else {
|
||||
int sl = poc ? ol_buflen(poc) : 0;
|
||||
if( poc ){
|
||||
m_poc = poc ? new SQT[sl+1] : NULL;
|
||||
if( m_poc ) memcpy( m_poc, poc, (sl+1)*sizeof(SQT) );
|
||||
}
|
||||
else
|
||||
m_poc = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void Init( const SQOT *ps ){
|
||||
m_own = true;
|
||||
if( ps ){
|
||||
int sl = ps ? ol_strlen(ps) : 0; // Length of string in characters (not bytes)
|
||||
int scl = 0; // Length of converted string in char/wchar_t count
|
||||
// How much storage needed?
|
||||
if( !use_latin1 && sizeof(SQT)<sizeof(SQOT) ){
|
||||
// Converting wchar_t => UTF8
|
||||
const SQOT *ps1 = ps; // It is wchar_t* here
|
||||
SQT tmp_buf[8];
|
||||
SQT *ptmp;
|
||||
while( *ps1 ){
|
||||
ptmp = tmp_buf;
|
||||
if( ol_writechar(ptmp,*ps1++) )
|
||||
scl += ol_charlen(tmp_buf);
|
||||
else
|
||||
scl++;
|
||||
}
|
||||
}
|
||||
else scl = sl; // Converting to wchar_t or Latin1, keep length
|
||||
|
||||
m_poc = new SQT[scl+1];
|
||||
if( !m_poc ) return;
|
||||
|
||||
// Convert
|
||||
SQT *poc = m_poc;
|
||||
while( *ps ){
|
||||
ol_writechar( poc, ol_char(ps) );
|
||||
ps += ol_charlen(ps);
|
||||
}
|
||||
*poc = 0; // Terminating zero
|
||||
}
|
||||
else
|
||||
m_poc = NULL;
|
||||
}
|
||||
|
||||
~SQCharBufImpl(){ Release(); }
|
||||
|
||||
void Release( ){
|
||||
if(m_poc && m_own )
|
||||
delete [] m_poc;
|
||||
m_poc = NULL;
|
||||
}
|
||||
|
||||
SQT* Set( const SQOT *ps ){
|
||||
Release( );
|
||||
Init( ps );
|
||||
return m_poc;
|
||||
}
|
||||
|
||||
operator SQT*() const { return m_poc; }
|
||||
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQT *ps){
|
||||
Release();
|
||||
Init( ps, false );
|
||||
return *this;
|
||||
}
|
||||
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQOT *ps){
|
||||
Release();
|
||||
Init( ps );
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Move string from other here - Note: Empties the input argument (other)
|
||||
SQCharBufImpl<SQT,SQOT,use_latin1>& operator = (const SQCharBufImpl<SQT,SQOT,use_latin1>& other){
|
||||
Release();
|
||||
m_poc = other.m_poc;
|
||||
m_own = other.m_own;
|
||||
SQT **psqt = (SQT**)&other.m_poc;
|
||||
*psqt = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
SQT *m_poc;
|
||||
bool m_own;
|
||||
};
|
||||
|
||||
typedef SQCharBufImpl<SQOtherChar, SQChar, bool(SQPLUS_USE_LATIN1)> SQOthCharBuf;
|
||||
typedef SQCharBufImpl<SQChar, SQOtherChar, bool(SQPLUS_USE_LATIN1)> SQDefCharBuf;
|
||||
typedef SQCharBufImpl<wchar_t, char, bool(SQPLUS_USE_LATIN1)> SQWCharBuf;
|
||||
typedef SQCharBufImpl<char, wchar_t, bool(SQPLUS_USE_LATIN1)> SQACharBuf;
|
||||
|
||||
#ifdef SQUNICODE
|
||||
// SQChar is wchar_t, convert to/from to either Latin1 or UTF8
|
||||
#define WC2SQ(s) s
|
||||
#define SQ2WC(s) s
|
||||
SQDefCharBuf CH2SQ( const char* ps );
|
||||
SQOthCharBuf SQ2CH( const wchar_t* pws );
|
||||
#else
|
||||
// SQChar is char, convert to/from wchar_t
|
||||
SQDefCharBuf WC2SQ( const wchar_t* pws );
|
||||
SQOthCharBuf SQ2WC( const char* pws );
|
||||
#define CH2SQ(s) s
|
||||
#define SQ2CH(s) s
|
||||
#endif
|
||||
|
||||
#endif // SQPLUS_CHARBUF_H
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,129 +1,129 @@
|
||||
#ifndef SQPLUSSETUP_H
|
||||
#define SQPLUSSETUP_H
|
||||
|
||||
// Setup file for SqPlus.
|
||||
// Comment / uncomment / define options below.
|
||||
|
||||
|
||||
// Inheritance in Squirrel allows one class to inherit a base class's
|
||||
// functions and variables.
|
||||
//
|
||||
// Variables are merged: if Derived has a var name 'val' and Base has
|
||||
// a var of the same name, the resulting var 'val' will take Derived's
|
||||
// initialization value.
|
||||
//
|
||||
// Functions are not merged, and can be called via Squirrel scoping rules.
|
||||
//
|
||||
// Define SQ_USE_CLASS_INHERITANCE to enable class inheritance support
|
||||
// (requires slightly more memory and adds some CPU overhead).
|
||||
//
|
||||
// Can also be useful for debugging, as class type information is
|
||||
// checked before dispatching instance function calls and before
|
||||
// accessing instance member variables.
|
||||
#define SQ_USE_CLASS_INHERITANCE
|
||||
|
||||
|
||||
// This is a new C++ template based inheritence scheme that uses no
|
||||
// additional memory per instance. To support offset between "this"
|
||||
// pointer in base and derived class, use a second class in:
|
||||
// SQClassDef< MyClass, MyBaseClass >.
|
||||
// NOTE: For new code SQ_USE_CLASS_INHERITANCE_SIMPLE is more
|
||||
// efficient than above method.
|
||||
//#define SQ_USE_CLASS_INHERITANCE_SIMPLE
|
||||
|
||||
// === Instance type info support ===
|
||||
#define SQ_SUPPORT_INSTANCE_TYPE_INFO
|
||||
|
||||
// === Constant argument and constant member function support ===
|
||||
// Define SQPLUS_CONST_OPT before including SqPlus.h for constant
|
||||
// argument + constant member function support.
|
||||
#define SQPLUS_CONST_OPT
|
||||
|
||||
|
||||
// === Uncomment to support smart pointer ===
|
||||
// Define SQPLUS_SMARTPOINTER_OPT before including SqPlus.h for
|
||||
// smartpointer member function + variable support
|
||||
//#define SQPLUS_SMARTPOINTER_OPT
|
||||
|
||||
|
||||
// === Function overloading support ===
|
||||
#define SQPLUS_OVERLOAD_OPT
|
||||
|
||||
// === Uncomment to support std::string ===
|
||||
// Requires that Squirrel is compiled with SQChar == char
|
||||
//#define SQPLUS_SUPPORT_STD_STRING
|
||||
|
||||
// === Uncomment to support typedef std::basic_string<SQChar> sq_std_string ===
|
||||
#define SQPLUS_SUPPORT_SQ_STD_STRING
|
||||
|
||||
// === Uncomment to support NULL INSTANCE arguments ===
|
||||
#define SQPLUS_SUPPORT_NULL_INSTANCES
|
||||
|
||||
// === Uncomment to disable copying of class instances ===
|
||||
// If classes being exposed have private or protected constructors
|
||||
// one cannot do assign (=) in template functions.
|
||||
//#define SQPLUS_DISABLE_COPY_INSTANCES
|
||||
|
||||
|
||||
// === Auto generating typemasks for registered functions ===
|
||||
// This is useful when using Squirrel interactively
|
||||
//#define SQPLUS_ENABLE_AUTO_TYPEMASK
|
||||
|
||||
// === Uncomment to generate a typeof function for each class ===
|
||||
// This is mostly for displaying function help from inside a Squirrel prompt
|
||||
//#define SQPLUS_ENABLE_TYPEOF
|
||||
|
||||
// === Uncomment to skip sq_argassert() ===
|
||||
//#define SQ_SKIP_ARG_ASSERT
|
||||
|
||||
// === GCC Inline template fix ===
|
||||
// Can solve problems when linking if GCC has problems with inline functions
|
||||
//#define GCC_INLINE_WORKAROUND
|
||||
|
||||
|
||||
// === MSVC cdecl member functions ===
|
||||
// Enable binding member functions with __cdecl calling convention under MSVC.
|
||||
// Mostly useful when linking with binaries from other compilers.
|
||||
#ifdef _MSC_VER
|
||||
//#define SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS
|
||||
#endif
|
||||
|
||||
|
||||
// === Generic Push/Pop/Match handlers ===
|
||||
// This enables using a 'fallback' set of Push/Get/Match that operates
|
||||
// on class level (not on template level). This opens for handling all
|
||||
// members of a certain class hierarchy using the same function
|
||||
// GenPush/GenGet/GenMatch overrides (provided the hierarchy has some
|
||||
// run-time type mechanism to use). They are used whenever an exact
|
||||
// template match is not found.
|
||||
//#define SQPLUS_USE_GENERIC_HANDLERS
|
||||
|
||||
|
||||
// === Sandbox VM ===
|
||||
// This enables giving one VM the role of 'sandbox' VM where scripts
|
||||
// of unknown origin may execute and not have access to any SqPlus
|
||||
// registered functions. All normal VMs have full access to script
|
||||
// functions, but the one given in SetSandboxVm() can only use std
|
||||
// Squirrel functions.
|
||||
//#define SQPLUS_USE_SANDBOX_VM
|
||||
|
||||
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) || defined(SQPLUS_SUPPORT_SQ_STD_STRING)
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
|
||||
// === Conversion of arguments from opposite char type ( char <=> wchar_t ) ===
|
||||
// Converts strings to opposite encoding in Push/Get handlers (UTF8 / Latin1)
|
||||
#define SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
|
||||
// === Whether 8 bit chars are treated as Latin1(1) or UTF8(0) ===
|
||||
// (leave undefined for undefined for automatic handling)
|
||||
#define SQPLUS_USE_LATIN1 1
|
||||
|
||||
// === Include system library bindings when creating VM:s in SquirrelVM::Init() ===
|
||||
// Define to bind to system lib when VM:s are created automatically in
|
||||
// SquirrelVM::Init()
|
||||
//#define SQPLUS_SQUIRRELVM_WITH_SYSTEMLIB
|
||||
|
||||
#endif // SQPLUSSETUP_H
|
||||
#ifndef SQPLUSSETUP_H
|
||||
#define SQPLUSSETUP_H
|
||||
|
||||
// Setup file for SqPlus.
|
||||
// Comment / uncomment / define options below.
|
||||
|
||||
|
||||
// Inheritance in Squirrel allows one class to inherit a base class's
|
||||
// functions and variables.
|
||||
//
|
||||
// Variables are merged: if Derived has a var name 'val' and Base has
|
||||
// a var of the same name, the resulting var 'val' will take Derived's
|
||||
// initialization value.
|
||||
//
|
||||
// Functions are not merged, and can be called via Squirrel scoping rules.
|
||||
//
|
||||
// Define SQ_USE_CLASS_INHERITANCE to enable class inheritance support
|
||||
// (requires slightly more memory and adds some CPU overhead).
|
||||
//
|
||||
// Can also be useful for debugging, as class type information is
|
||||
// checked before dispatching instance function calls and before
|
||||
// accessing instance member variables.
|
||||
#define SQ_USE_CLASS_INHERITANCE
|
||||
|
||||
|
||||
// This is a new C++ template based inheritence scheme that uses no
|
||||
// additional memory per instance. To support offset between "this"
|
||||
// pointer in base and derived class, use a second class in:
|
||||
// SQClassDef< MyClass, MyBaseClass >.
|
||||
// NOTE: For new code SQ_USE_CLASS_INHERITANCE_SIMPLE is more
|
||||
// efficient than above method.
|
||||
//#define SQ_USE_CLASS_INHERITANCE_SIMPLE
|
||||
|
||||
// === Instance type info support ===
|
||||
#define SQ_SUPPORT_INSTANCE_TYPE_INFO
|
||||
|
||||
// === Constant argument and constant member function support ===
|
||||
// Define SQPLUS_CONST_OPT before including SqPlus.h for constant
|
||||
// argument + constant member function support.
|
||||
#define SQPLUS_CONST_OPT
|
||||
|
||||
|
||||
// === Uncomment to support smart pointer ===
|
||||
// Define SQPLUS_SMARTPOINTER_OPT before including SqPlus.h for
|
||||
// smartpointer member function + variable support
|
||||
//#define SQPLUS_SMARTPOINTER_OPT
|
||||
|
||||
|
||||
// === Function overloading support ===
|
||||
#define SQPLUS_OVERLOAD_OPT
|
||||
|
||||
// === Uncomment to support std::string ===
|
||||
// Requires that Squirrel is compiled with SQChar == char
|
||||
//#define SQPLUS_SUPPORT_STD_STRING
|
||||
|
||||
// === Uncomment to support typedef std::basic_string<SQChar> sq_std_string ===
|
||||
#define SQPLUS_SUPPORT_SQ_STD_STRING
|
||||
|
||||
// === Uncomment to support NULL INSTANCE arguments ===
|
||||
#define SQPLUS_SUPPORT_NULL_INSTANCES
|
||||
|
||||
// === Uncomment to disable copying of class instances ===
|
||||
// If classes being exposed have private or protected constructors
|
||||
// one cannot do assign (=) in template functions.
|
||||
//#define SQPLUS_DISABLE_COPY_INSTANCES
|
||||
|
||||
|
||||
// === Auto generating typemasks for registered functions ===
|
||||
// This is useful when using Squirrel interactively
|
||||
//#define SQPLUS_ENABLE_AUTO_TYPEMASK
|
||||
|
||||
// === Uncomment to generate a typeof function for each class ===
|
||||
// This is mostly for displaying function help from inside a Squirrel prompt
|
||||
//#define SQPLUS_ENABLE_TYPEOF
|
||||
|
||||
// === Uncomment to skip sq_argassert() ===
|
||||
//#define SQ_SKIP_ARG_ASSERT
|
||||
|
||||
// === GCC Inline template fix ===
|
||||
// Can solve problems when linking if GCC has problems with inline functions
|
||||
//#define GCC_INLINE_WORKAROUND
|
||||
|
||||
|
||||
// === MSVC cdecl member functions ===
|
||||
// Enable binding member functions with __cdecl calling convention under MSVC.
|
||||
// Mostly useful when linking with binaries from other compilers.
|
||||
#ifdef _MSC_VER
|
||||
//#define SQPLUS_ENABLE_CDECL_MEMBER_FUNCTIONS
|
||||
#endif
|
||||
|
||||
|
||||
// === Generic Push/Pop/Match handlers ===
|
||||
// This enables using a 'fallback' set of Push/Get/Match that operates
|
||||
// on class level (not on template level). This opens for handling all
|
||||
// members of a certain class hierarchy using the same function
|
||||
// GenPush/GenGet/GenMatch overrides (provided the hierarchy has some
|
||||
// run-time type mechanism to use). They are used whenever an exact
|
||||
// template match is not found.
|
||||
//#define SQPLUS_USE_GENERIC_HANDLERS
|
||||
|
||||
|
||||
// === Sandbox VM ===
|
||||
// This enables giving one VM the role of 'sandbox' VM where scripts
|
||||
// of unknown origin may execute and not have access to any SqPlus
|
||||
// registered functions. All normal VMs have full access to script
|
||||
// functions, but the one given in SetSandboxVm() can only use std
|
||||
// Squirrel functions.
|
||||
//#define SQPLUS_USE_SANDBOX_VM
|
||||
|
||||
|
||||
#if defined(SQPLUS_SUPPORT_STD_STRING) || defined(SQPLUS_SUPPORT_SQ_STD_STRING)
|
||||
# include <string>
|
||||
#endif
|
||||
|
||||
|
||||
// === Conversion of arguments from opposite char type ( char <=> wchar_t ) ===
|
||||
// Converts strings to opposite encoding in Push/Get handlers (UTF8 / Latin1)
|
||||
#define SQPLUS_AUTOCONVERT_OTHER_CHAR
|
||||
|
||||
// === Whether 8 bit chars are treated as Latin1(1) or UTF8(0) ===
|
||||
// (leave undefined for undefined for automatic handling)
|
||||
#define SQPLUS_USE_LATIN1 1
|
||||
|
||||
// === Include system library bindings when creating VM:s in SquirrelVM::Init() ===
|
||||
// Define to bind to system lib when VM:s are created automatically in
|
||||
// SquirrelVM::Init()
|
||||
//#define SQPLUS_SQUIRRELVM_WITH_SYSTEMLIB
|
||||
|
||||
#endif // SQPLUSSETUP_H
|
@ -1,141 +1,141 @@
|
||||
// SqPlusSmartPointer.h
|
||||
// SqPlus smart pointer member function support created by James Whitworth.
|
||||
// Modular integration 07/11/07 James Whitworth.
|
||||
// you must define the function:
|
||||
// unsigned char* getSmartPointerPointee(unsigned char*) {
|
||||
// return &(MySmartPointer->pointee);
|
||||
// }
|
||||
// somewhere in your program so it can correctly lookup member variables on the class pointed to
|
||||
// by your smart pointer.
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
#undef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
enum VarAccessType {VAR_ACCESS_READ_WRITE=0,VAR_ACCESS_READ_ONLY=1<<0,VAR_ACCESS_CONSTANT=1<<1,VAR_ACCESS_STATIC=1<<2,VAR_ACCESS_SMARTPOINTER=1<<3};
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
#undef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
// classType is the type of the member variable's containing class.
|
||||
template<typename T>
|
||||
void
|
||||
RegisterSmartInstanceVariable(SquirrelObject & so,
|
||||
ClassTypeBase *classType,
|
||||
T *var,
|
||||
const SQChar *scriptVarName,
|
||||
VarAccessType access = VAR_ACCESS_READ_WRITE)
|
||||
{
|
||||
VarRef *pvr = createVarRef(so,scriptVarName);
|
||||
|
||||
// var must be passed in as &obj->var, where obj = 0
|
||||
// (the address is the offset), or as static/global address.
|
||||
void *offsetOrAddrOrConst = static_cast<void*>(var);
|
||||
*pvr = VarRef(offsetOrAddrOrConst,
|
||||
TypeInfo<T>(),
|
||||
classType,
|
||||
ClassType<T>::type(),
|
||||
sizeof(*var),
|
||||
access);
|
||||
pvr->m_access |= VAR_ACCESS_SMARTPOINTER;
|
||||
createInstanceSetGetHandlers(so);
|
||||
}
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
#undef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
template<typename Callee,typename Pointee,typename Func>
|
||||
class DirectCallSmartInstanceMemberFunction {
|
||||
public:
|
||||
static inline int Dispatch(HSQUIRRELVM v) {
|
||||
DirectCallInstanceFuncPicker<Callee, Func> p(v);
|
||||
if (!p.instance || !p.func) {
|
||||
sq_throwerror(v, _SC("Invalid Instance Type"));
|
||||
}
|
||||
Pointee *pointeeInstance = static_cast<Pointee*>(p.instance->get());
|
||||
return
|
||||
!pointeeInstance ? sq_throwerror(v, _SC("SmartPointer Pointee NULL")) :
|
||||
Call(*pointeeInstance, *(p.func), v, 2);
|
||||
}
|
||||
};
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
#undef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
|
||||
template<typename Callee,typename Pointee,typename Func>
|
||||
inline void sq_pushdirectsmartinstanceclosure(HSQUIRRELVM v,const Callee & callee,const Pointee & pointee,Func func,SQUnsignedInteger nupvalues) {
|
||||
unsigned char * up = (unsigned char *)sq_newuserdata(v,sizeof(func)); // Also pushed on stack.
|
||||
memcpy(up,&func,sizeof(func));
|
||||
sq_newclosure(v,DirectCallSmartInstanceMemberFunction<Callee,Pointee,Func>::Dispatch,nupvalues+1);
|
||||
} // sq_pushdirectinstanceclosure
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
#undef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
|
||||
template<typename Callee, typename Pointee, typename Func>
|
||||
inline void RegisterSmartInstance(HSQUIRRELVM v,HSQOBJECT hclass,Callee & callee,Pointee & pointee,Func func,const SQChar * name) {
|
||||
sq_pushobject(v,hclass);
|
||||
sq_pushstring(v,name,-1);
|
||||
sq_pushdirectsmartinstanceclosure(v,callee,pointee,func,0);
|
||||
sq_createslot(v,-3);
|
||||
sq_poptop(v); // Remove hclass.
|
||||
} // RegisterInstance
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
#undef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
|
||||
// Register a smartpointer member function.
|
||||
template<typename Pointee, typename Func>
|
||||
SQClassDefBase & smartFunc(Func pfunc,const SQChar * name) {
|
||||
RegisterSmartInstance(v,newClass.GetObjectHandle(),*(TClassType *)0,*(Pointee *)0,pfunc,name);
|
||||
return *this;
|
||||
} // func
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
#undef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
|
||||
// Register a member variable.
|
||||
template<typename Pointee, typename VarType>
|
||||
SQClassDefBase & smartVar(VarType Pointee::* pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_WRITE) {
|
||||
struct CV {
|
||||
VarType Pointee::* var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterSmartInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,access);
|
||||
return *this;
|
||||
} // var
|
||||
|
||||
// Register a member variable as a UserPointer (read only).
|
||||
template<typename Pointee, typename VarType>
|
||||
SQClassDefBase & smartVarAsUserPointer(VarType Pointee::* pvar,const SQChar * name) {
|
||||
struct CV {
|
||||
VarType Pointee::* var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterSmartInstanceVariable(newClass,ClassType<TClassType>::type(),*(SQAnything **)&cv,name,VAR_ACCESS_READ_ONLY);
|
||||
return *this;
|
||||
} // varAsUserPointer
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
#undef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
extern unsigned char* getSmartPointerPointee(unsigned char*);
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
#undef SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
if(vr->m_access & VAR_ACCESS_SMARTPOINTER) {
|
||||
up = reinterpret_cast<char*>(
|
||||
getSmartPointerPointee(reinterpret_cast<unsigned char*>(up))
|
||||
);
|
||||
}
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
|
||||
// SqPlusSmartPointer.h
|
||||
// SqPlusSmartPointer.h
|
||||
// SqPlus smart pointer member function support created by James Whitworth.
|
||||
// Modular integration 07/11/07 James Whitworth.
|
||||
// you must define the function:
|
||||
// unsigned char* getSmartPointerPointee(unsigned char*) {
|
||||
// return &(MySmartPointer->pointee);
|
||||
// }
|
||||
// somewhere in your program so it can correctly lookup member variables on the class pointed to
|
||||
// by your smart pointer.
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
#undef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
enum VarAccessType {VAR_ACCESS_READ_WRITE=0,VAR_ACCESS_READ_ONLY=1<<0,VAR_ACCESS_CONSTANT=1<<1,VAR_ACCESS_STATIC=1<<2,VAR_ACCESS_SMARTPOINTER=1<<3};
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_ACCESSTYPE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
#undef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
// classType is the type of the member variable's containing class.
|
||||
template<typename T>
|
||||
void
|
||||
RegisterSmartInstanceVariable(SquirrelObject & so,
|
||||
ClassTypeBase *classType,
|
||||
T *var,
|
||||
const SQChar *scriptVarName,
|
||||
VarAccessType access = VAR_ACCESS_READ_WRITE)
|
||||
{
|
||||
VarRef *pvr = createVarRef(so,scriptVarName);
|
||||
|
||||
// var must be passed in as &obj->var, where obj = 0
|
||||
// (the address is the offset), or as static/global address.
|
||||
void *offsetOrAddrOrConst = static_cast<void*>(var);
|
||||
*pvr = VarRef(offsetOrAddrOrConst,
|
||||
TypeInfo<T>(),
|
||||
classType,
|
||||
ClassType<T>::type(),
|
||||
sizeof(*var),
|
||||
access);
|
||||
pvr->m_access |= VAR_ACCESS_SMARTPOINTER;
|
||||
createInstanceSetGetHandlers(so);
|
||||
}
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_REGISTER_VARIABLE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
#undef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
template<typename Callee,typename Pointee,typename Func>
|
||||
class DirectCallSmartInstanceMemberFunction {
|
||||
public:
|
||||
static inline int Dispatch(HSQUIRRELVM v) {
|
||||
DirectCallInstanceFuncPicker<Callee, Func> p(v);
|
||||
if (!p.instance || !p.func) {
|
||||
sq_throwerror(v, _SC("Invalid Instance Type"));
|
||||
}
|
||||
Pointee *pointeeInstance = static_cast<Pointee*>(p.instance->get());
|
||||
return
|
||||
!pointeeInstance ? sq_throwerror(v, _SC("SmartPointer Pointee NULL")) :
|
||||
Call(*pointeeInstance, *(p.func), v, 2);
|
||||
}
|
||||
};
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_DISPATCH
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
#undef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
|
||||
template<typename Callee,typename Pointee,typename Func>
|
||||
inline void sq_pushdirectsmartinstanceclosure(HSQUIRRELVM v,const Callee & callee,const Pointee & pointee,Func func,SQUnsignedInteger nupvalues) {
|
||||
unsigned char * up = (unsigned char *)sq_newuserdata(v,sizeof(func)); // Also pushed on stack.
|
||||
memcpy(up,&func,sizeof(func));
|
||||
sq_newclosure(v,DirectCallSmartInstanceMemberFunction<Callee,Pointee,Func>::Dispatch,nupvalues+1);
|
||||
} // sq_pushdirectinstanceclosure
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_DIRECT_CLOSURE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
#undef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
|
||||
template<typename Callee, typename Pointee, typename Func>
|
||||
inline void RegisterSmartInstance(HSQUIRRELVM v,HSQOBJECT hclass,Callee & callee,Pointee & pointee,Func func,const SQChar * name) {
|
||||
sq_pushobject(v,hclass);
|
||||
sq_pushstring(v,name,-1);
|
||||
sq_pushdirectsmartinstanceclosure(v,callee,pointee,func,0);
|
||||
sq_createslot(v,-3);
|
||||
sq_poptop(v); // Remove hclass.
|
||||
} // RegisterInstance
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_REGISTER_INSTANCE
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
#undef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
|
||||
// Register a smartpointer member function.
|
||||
template<typename Pointee, typename Func>
|
||||
SQClassDefBase & smartFunc(Func pfunc,const SQChar * name) {
|
||||
RegisterSmartInstance(v,newClass.GetObjectHandle(),*(TClassType *)0,*(Pointee *)0,pfunc,name);
|
||||
return *this;
|
||||
} // func
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_FUNC
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
#undef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
|
||||
// Register a member variable.
|
||||
template<typename Pointee, typename VarType>
|
||||
SQClassDefBase & smartVar(VarType Pointee::* pvar,const SQChar * name,VarAccessType access=VAR_ACCESS_READ_WRITE) {
|
||||
struct CV {
|
||||
VarType Pointee::* var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterSmartInstanceVariable(newClass,ClassType<TClassType>::type(),*(VarType **)&cv,name,access);
|
||||
return *this;
|
||||
} // var
|
||||
|
||||
// Register a member variable as a UserPointer (read only).
|
||||
template<typename Pointee, typename VarType>
|
||||
SQClassDefBase & smartVarAsUserPointer(VarType Pointee::* pvar,const SQChar * name) {
|
||||
struct CV {
|
||||
VarType Pointee::* var;
|
||||
} cv; // Cast Variable helper.
|
||||
cv.var = pvar;
|
||||
RegisterSmartInstanceVariable(newClass,ClassType<TClassType>::type(),*(SQAnything **)&cv,name,VAR_ACCESS_READ_ONLY);
|
||||
return *this;
|
||||
} // varAsUserPointer
|
||||
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CLASS_DEF_VAR
|
||||
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
#undef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
extern unsigned char* getSmartPointerPointee(unsigned char*);
|
||||
#endif
|
||||
|
||||
#ifdef SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
#undef SQPLUS_SMARTPOINTER_INSTANCE_VARINFO
|
||||
if(vr->m_access & VAR_ACCESS_SMARTPOINTER) {
|
||||
up = reinterpret_cast<char*>(
|
||||
getSmartPointerPointee(reinterpret_cast<unsigned char*>(up))
|
||||
);
|
||||
}
|
||||
#endif // #ifdef SQPLUS_SMARTPOINTER_CPP_DECLARATION
|
||||
|
||||
// SqPlusSmartPointer.h
|
@ -1,169 +1,169 @@
|
||||
|
||||
// File to automatically generate a typemask for a function
|
||||
|
||||
// Will generate type masks that accepts Instance pointer or null
|
||||
#ifndef SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
#define SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
#endif
|
||||
|
||||
// Macros to reduce typing: (P1), (P1,P2), (P1,P2,P3), ...
|
||||
#define P_0
|
||||
#define P_1 P1
|
||||
#define P_2 P_1,P2
|
||||
#define P_3 P_2,P3
|
||||
#define P_4 P_3,P4
|
||||
#define P_5 P_4,P5
|
||||
#define P_6 P_5,P6
|
||||
#define P_7 P_6,P7
|
||||
|
||||
// Macros to reduce typing: (typename P1), (typename P1,typename P2), ...
|
||||
#define PTN_0
|
||||
#define PTN_1 typename P1
|
||||
#define PTN_2 PTN_1,typename P2
|
||||
#define PTN_3 PTN_2,typename P3
|
||||
#define PTN_4 PTN_3,typename P4
|
||||
#define PTN_5 PTN_4,typename P5
|
||||
#define PTN_6 PTN_5,typename P6
|
||||
#define PTN_7 PTN_6,typename P7
|
||||
|
||||
// Include a comma first in list: ,typename P1,typename P2
|
||||
#define PTNC_0
|
||||
#define PTNC_1 ,PTN_1
|
||||
#define PTNC_2 ,PTN_2
|
||||
#define PTNC_3 ,PTN_3
|
||||
#define PTNC_4 ,PTN_4
|
||||
#define PTNC_5 ,PTN_5
|
||||
#define PTNC_6 ,PTN_6
|
||||
#define PTNC_7 ,PTN_7
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scstrcpy wcscpy
|
||||
#else
|
||||
#define scstrcpy strcpy
|
||||
#endif
|
||||
|
||||
inline const SQChar* strappchar(SQChar *buf, SQChar *in, SQChar ch){
|
||||
int l=scstrlen(in);
|
||||
scstrcpy(buf,in);
|
||||
buf[l] = ch;
|
||||
#ifdef SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
if( ch=='x' ){
|
||||
buf[++l] = '|'; // Also accept NULL pointers
|
||||
buf[++l] = 'o';
|
||||
}
|
||||
#endif
|
||||
buf[l+1] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct sqTypeMask { };
|
||||
|
||||
|
||||
// Return type not included in type mask, delegate to void case
|
||||
|
||||
// Base case, no arguments
|
||||
template<typename RT>
|
||||
struct sqTypeMask<RT(*)()> {
|
||||
static const SQChar *Get(){
|
||||
static SQChar buf[64];
|
||||
//buf[0] = _SC('t');
|
||||
//buf[1] = 0;
|
||||
//strcpy(buf,"t|x"); // Accept both instance and table, we don't use param anyway
|
||||
buf[0] = _SC('.'); // Accept anything (not used)
|
||||
buf[1] = 0;
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
||||
// Recursive case, peel of one arg at each level
|
||||
#define DECLARE_RT_SQTYPEMASK(N,M) \
|
||||
template<typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(*)(P_##N)> { \
|
||||
static const SQChar *Get(){ \
|
||||
static SQChar buf[10]; \
|
||||
return strappchar(buf, (SQChar*)sqTypeMask<RT(*)(P_##M)>::Get(), \
|
||||
(SQChar)TypeInfo<P##N>::TypeMask); \
|
||||
} \
|
||||
};
|
||||
|
||||
DECLARE_RT_SQTYPEMASK(1,0)
|
||||
DECLARE_RT_SQTYPEMASK(2,1)
|
||||
DECLARE_RT_SQTYPEMASK(3,2)
|
||||
DECLARE_RT_SQTYPEMASK(4,3)
|
||||
DECLARE_RT_SQTYPEMASK(5,4)
|
||||
DECLARE_RT_SQTYPEMASK(6,5)
|
||||
DECLARE_RT_SQTYPEMASK(7,6)
|
||||
|
||||
|
||||
// Difference to above is that 1st param is instance instead of table
|
||||
|
||||
#define DECLARE_RT_MEMBER_SQTYPEMASK(N,QUAL) \
|
||||
template<typename Callee, typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(Callee::*)(P_##N) QUAL> { \
|
||||
static const SQChar *Get(){ \
|
||||
SQChar *buf = (SQChar*)sqTypeMask<RT(*)(P_##N)>::Get(); \
|
||||
buf[0] = _SC('x'); \
|
||||
return buf; \
|
||||
} \
|
||||
};
|
||||
|
||||
// buf[1] = 0; \
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(0,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(1,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(2,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(3,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(4,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(5,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(6,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(7,)
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(0,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(1,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(2,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(3,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(4,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(5,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(6,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(7,const)
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
// Difference to above is we're using __cdecl calling convention here
|
||||
// Only makes sense for MSVC where member functions can have different
|
||||
// calling conventions (__cdecl or __thiscall)
|
||||
|
||||
#define DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(N,QUAL) \
|
||||
template<typename Callee, typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(__cdecl Callee::*)(P_##N) QUAL> { \
|
||||
static const SQChar *Get(){ \
|
||||
SQChar *buf = (SQChar*)sqTypeMask<RT(*)(P_##N)>::Get(); \
|
||||
buf[0] = _SC('x'); \
|
||||
return buf; \
|
||||
} \
|
||||
};
|
||||
|
||||
// buf[1] = 0; \
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(0,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(1,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(2,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(3,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(4,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(5,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(6,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(7,)
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(0,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(1,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(2,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(3,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(4,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(5,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(6,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(7,const)
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
||||
|
||||
// File to automatically generate a typemask for a function
|
||||
|
||||
// Will generate type masks that accepts Instance pointer or null
|
||||
#ifndef SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
#define SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
#endif
|
||||
|
||||
// Macros to reduce typing: (P1), (P1,P2), (P1,P2,P3), ...
|
||||
#define P_0
|
||||
#define P_1 P1
|
||||
#define P_2 P_1,P2
|
||||
#define P_3 P_2,P3
|
||||
#define P_4 P_3,P4
|
||||
#define P_5 P_4,P5
|
||||
#define P_6 P_5,P6
|
||||
#define P_7 P_6,P7
|
||||
|
||||
// Macros to reduce typing: (typename P1), (typename P1,typename P2), ...
|
||||
#define PTN_0
|
||||
#define PTN_1 typename P1
|
||||
#define PTN_2 PTN_1,typename P2
|
||||
#define PTN_3 PTN_2,typename P3
|
||||
#define PTN_4 PTN_3,typename P4
|
||||
#define PTN_5 PTN_4,typename P5
|
||||
#define PTN_6 PTN_5,typename P6
|
||||
#define PTN_7 PTN_6,typename P7
|
||||
|
||||
// Include a comma first in list: ,typename P1,typename P2
|
||||
#define PTNC_0
|
||||
#define PTNC_1 ,PTN_1
|
||||
#define PTNC_2 ,PTN_2
|
||||
#define PTNC_3 ,PTN_3
|
||||
#define PTNC_4 ,PTN_4
|
||||
#define PTNC_5 ,PTN_5
|
||||
#define PTNC_6 ,PTN_6
|
||||
#define PTNC_7 ,PTN_7
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scstrcpy wcscpy
|
||||
#else
|
||||
#define scstrcpy strcpy
|
||||
#endif
|
||||
|
||||
inline const SQChar* strappchar(SQChar *buf, SQChar *in, SQChar ch){
|
||||
int l=scstrlen(in);
|
||||
scstrcpy(buf,in);
|
||||
buf[l] = ch;
|
||||
#ifdef SQPLUS_ACCEPT_NULL_INSTANCE
|
||||
if( ch=='x' ){
|
||||
buf[++l] = '|'; // Also accept NULL pointers
|
||||
buf[++l] = 'o';
|
||||
}
|
||||
#endif
|
||||
buf[l+1] = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
struct sqTypeMask { };
|
||||
|
||||
|
||||
// Return type not included in type mask, delegate to void case
|
||||
|
||||
// Base case, no arguments
|
||||
template<typename RT>
|
||||
struct sqTypeMask<RT(*)()> {
|
||||
static const SQChar *Get(){
|
||||
static SQChar buf[64];
|
||||
//buf[0] = _SC('t');
|
||||
//buf[1] = 0;
|
||||
//strcpy(buf,"t|x"); // Accept both instance and table, we don't use param anyway
|
||||
buf[0] = _SC('.'); // Accept anything (not used)
|
||||
buf[1] = 0;
|
||||
return buf;
|
||||
}
|
||||
};
|
||||
|
||||
// Recursive case, peel of one arg at each level
|
||||
#define DECLARE_RT_SQTYPEMASK(N,M) \
|
||||
template<typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(*)(P_##N)> { \
|
||||
static const SQChar *Get(){ \
|
||||
static SQChar buf[10]; \
|
||||
return strappchar(buf, (SQChar*)sqTypeMask<RT(*)(P_##M)>::Get(), \
|
||||
(SQChar)TypeInfo<P##N>::TypeMask); \
|
||||
} \
|
||||
};
|
||||
|
||||
DECLARE_RT_SQTYPEMASK(1,0)
|
||||
DECLARE_RT_SQTYPEMASK(2,1)
|
||||
DECLARE_RT_SQTYPEMASK(3,2)
|
||||
DECLARE_RT_SQTYPEMASK(4,3)
|
||||
DECLARE_RT_SQTYPEMASK(5,4)
|
||||
DECLARE_RT_SQTYPEMASK(6,5)
|
||||
DECLARE_RT_SQTYPEMASK(7,6)
|
||||
|
||||
|
||||
// Difference to above is that 1st param is instance instead of table
|
||||
|
||||
#define DECLARE_RT_MEMBER_SQTYPEMASK(N,QUAL) \
|
||||
template<typename Callee, typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(Callee::*)(P_##N) QUAL> { \
|
||||
static const SQChar *Get(){ \
|
||||
SQChar *buf = (SQChar*)sqTypeMask<RT(*)(P_##N)>::Get(); \
|
||||
buf[0] = _SC('x'); \
|
||||
return buf; \
|
||||
} \
|
||||
};
|
||||
|
||||
// buf[1] = 0; \
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(0,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(1,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(2,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(3,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(4,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(5,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(6,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(7,)
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(0,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(1,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(2,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(3,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(4,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(5,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(6,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK(7,const)
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
// Difference to above is we're using __cdecl calling convention here
|
||||
// Only makes sense for MSVC where member functions can have different
|
||||
// calling conventions (__cdecl or __thiscall)
|
||||
|
||||
#define DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(N,QUAL) \
|
||||
template<typename Callee, typename RT PTNC_##N> \
|
||||
struct sqTypeMask<RT(__cdecl Callee::*)(P_##N) QUAL> { \
|
||||
static const SQChar *Get(){ \
|
||||
SQChar *buf = (SQChar*)sqTypeMask<RT(*)(P_##N)>::Get(); \
|
||||
buf[0] = _SC('x'); \
|
||||
return buf; \
|
||||
} \
|
||||
};
|
||||
|
||||
// buf[1] = 0; \
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(0,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(1,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(2,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(3,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(4,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(5,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(6,)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(7,)
|
||||
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(0,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(1,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(2,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(3,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(4,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(5,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(6,const)
|
||||
DECLARE_RT_MEMBER_SQTYPEMASK_CDECL(7,const)
|
||||
|
||||
#endif // _MSC_VER
|
||||
|
@ -1,133 +1,133 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Simple conversion routines, to, from UTF8 and full Unicode character
|
||||
// (using int).
|
||||
//
|
||||
|
||||
// Only when needed
|
||||
#if !defined(SQPLUS_USE_LATIN1) || SQPLUS_USE_LATIN1==0
|
||||
|
||||
static char g_utf8_length[256];
|
||||
static int g_did_init_length;
|
||||
|
||||
void sqplus_init_utf8_lengths() {
|
||||
// Fill in lengths in array above
|
||||
for( int lb=0; lb<256; lb++ ){
|
||||
int l = -1;
|
||||
if( !(lb&0x80) ) l=1;
|
||||
else if( (lb&0xE0)==0xC0 ) l=2;
|
||||
else if( (lb&0xF0)==0xE0 ) l=3;
|
||||
else if( (lb&0xF8)==0xF0 ) l=4;
|
||||
else if( (lb&0xFC)==0xF8 ) l=5;
|
||||
else if( (lb&0xFE)==0xFC ) l=6;
|
||||
g_utf8_length[lb] = l;
|
||||
}
|
||||
g_did_init_length = 1;
|
||||
}
|
||||
|
||||
// Length of a UTF8 encoded Unicode character
|
||||
int sqplus_utf8_len(int lead_byte){
|
||||
if( !(lead_byte&0x80) ) return 1; // Special case, make faster
|
||||
if( !g_did_init_length )
|
||||
sqplus_init_utf8_lengths();
|
||||
|
||||
return g_utf8_length[(unsigned char)lead_byte];
|
||||
}
|
||||
|
||||
int sqplus_utf8_len_first(const char* pc){
|
||||
int lb = *(unsigned char*)pc;
|
||||
if( !(lb&0x80) ) return 1; // Special case, make faster
|
||||
if( !g_did_init_length )
|
||||
sqplus_init_utf8_lengths();
|
||||
|
||||
int l = g_utf8_length[(unsigned char)lb];
|
||||
if( l>0 ) return l;
|
||||
|
||||
// Invalid UTF8 lead byte. Look for next valid character.
|
||||
const char *pc1 = pc+1;
|
||||
while( ((*pc1)&0xC0)==0x80 )
|
||||
pc1++;
|
||||
return int(pc1 - pc);
|
||||
}
|
||||
|
||||
|
||||
// Length of a UTF8 encoded Unicode string (number of Unicode characters)
|
||||
int sqplus_utf8_strlen(const char *str) {
|
||||
if( !str ) return 0;
|
||||
int l, tl=0;
|
||||
while( *str ){
|
||||
l = sqplus_utf8_len_first(str);
|
||||
str += l;
|
||||
tl++;
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
// Convert one UTF8 encoded character to Unicode point
|
||||
int sqplus_utf8_to_wchar(int *result, const char *string){
|
||||
int res=-1;
|
||||
|
||||
// Assume argument pointers to be OK
|
||||
unsigned char ch = *string;
|
||||
int l = sqplus_utf8_len(ch);
|
||||
|
||||
if( l<1 ) return -1;
|
||||
int wc = l>1 ? (ch&(0x7F>>l)) : ch;
|
||||
while( l>1 ){
|
||||
wc = (wc<<6) + (*++string & 0x3F);
|
||||
l--;
|
||||
}
|
||||
*result = wc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert one Unicode point to UTF8 encoded version.
|
||||
// Checks if output fits in 1/4/6 bytes buffer.
|
||||
int sqplus_wchar_to_utf8(char *s, int wc, int size){
|
||||
if( size<1 ) return -1;
|
||||
if( (unsigned int)wc>=0x80000000 ) return -2;
|
||||
|
||||
// Single byte case
|
||||
if( wc<0x80 ){
|
||||
*s = (char)wc;
|
||||
//*s = (char)wc&0x7F;
|
||||
return 1;
|
||||
}
|
||||
if( size<4 ) return -3;
|
||||
|
||||
// Two or more UTF8 bytes
|
||||
int p = 1; // Index of last UTF8 byte
|
||||
if( wc>0x7FF ){ // 11 bits
|
||||
// Three or more UTF8 bytes
|
||||
p++; // p>=2
|
||||
if( wc>0xFFFF ){ // 16 bits
|
||||
// Four or more UTF8 bytes
|
||||
p++; // p>=3
|
||||
if( wc>0x1FFFFF ){ // 21 bits
|
||||
// Five or more UTF8 bytes
|
||||
if( size<6 ) return -3;
|
||||
p++; // p>=4 UTF8 bytes
|
||||
if( wc>0x3FFFFFF ){ // 26 bits
|
||||
// Six UTF8 bytes
|
||||
p++; // p>=5
|
||||
if( (unsigned int)wc>(unsigned int)0x7FFFFFF ){ // 31 bits
|
||||
// Would need 7 UTF8 bytes. Not supported.
|
||||
return -10;
|
||||
}
|
||||
s[p-4] = 0x80 | ((wc>>24)&0x3F); // Bit 24..29
|
||||
}
|
||||
s[p-3] = 0x80 | ((wc>>18)&0x3F); // Bit 18..23
|
||||
}
|
||||
s[p-2] = 0x80 | ((wc>>12)&0x3F); // Bit 12..17
|
||||
}
|
||||
s[p-1] = 0x80 | ((wc>>6)&0x3F); // Bit 6..11
|
||||
}
|
||||
s[p] = 0x80 | (wc&0x3F); // Bit 0..5
|
||||
s[0] = (0xFC << (5-p)) | (wc>>(p*6));
|
||||
|
||||
return p+1;
|
||||
}
|
||||
|
||||
#endif // #if !defined(SQPLUS_USE_LATIN1) || SQPLUS_USE_LATIN1==0
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// Simple conversion routines, to, from UTF8 and full Unicode character
|
||||
// (using int).
|
||||
//
|
||||
|
||||
// Only when needed
|
||||
#if !defined(SQPLUS_USE_LATIN1) || SQPLUS_USE_LATIN1==0
|
||||
|
||||
static char g_utf8_length[256];
|
||||
static int g_did_init_length;
|
||||
|
||||
void sqplus_init_utf8_lengths() {
|
||||
// Fill in lengths in array above
|
||||
for( int lb=0; lb<256; lb++ ){
|
||||
int l = -1;
|
||||
if( !(lb&0x80) ) l=1;
|
||||
else if( (lb&0xE0)==0xC0 ) l=2;
|
||||
else if( (lb&0xF0)==0xE0 ) l=3;
|
||||
else if( (lb&0xF8)==0xF0 ) l=4;
|
||||
else if( (lb&0xFC)==0xF8 ) l=5;
|
||||
else if( (lb&0xFE)==0xFC ) l=6;
|
||||
g_utf8_length[lb] = l;
|
||||
}
|
||||
g_did_init_length = 1;
|
||||
}
|
||||
|
||||
// Length of a UTF8 encoded Unicode character
|
||||
int sqplus_utf8_len(int lead_byte){
|
||||
if( !(lead_byte&0x80) ) return 1; // Special case, make faster
|
||||
if( !g_did_init_length )
|
||||
sqplus_init_utf8_lengths();
|
||||
|
||||
return g_utf8_length[(unsigned char)lead_byte];
|
||||
}
|
||||
|
||||
int sqplus_utf8_len_first(const char* pc){
|
||||
int lb = *(unsigned char*)pc;
|
||||
if( !(lb&0x80) ) return 1; // Special case, make faster
|
||||
if( !g_did_init_length )
|
||||
sqplus_init_utf8_lengths();
|
||||
|
||||
int l = g_utf8_length[(unsigned char)lb];
|
||||
if( l>0 ) return l;
|
||||
|
||||
// Invalid UTF8 lead byte. Look for next valid character.
|
||||
const char *pc1 = pc+1;
|
||||
while( ((*pc1)&0xC0)==0x80 )
|
||||
pc1++;
|
||||
return int(pc1 - pc);
|
||||
}
|
||||
|
||||
|
||||
// Length of a UTF8 encoded Unicode string (number of Unicode characters)
|
||||
int sqplus_utf8_strlen(const char *str) {
|
||||
if( !str ) return 0;
|
||||
int l, tl=0;
|
||||
while( *str ){
|
||||
l = sqplus_utf8_len_first(str);
|
||||
str += l;
|
||||
tl++;
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
// Convert one UTF8 encoded character to Unicode point
|
||||
int sqplus_utf8_to_wchar(int *result, const char *string){
|
||||
int res=-1;
|
||||
|
||||
// Assume argument pointers to be OK
|
||||
unsigned char ch = *string;
|
||||
int l = sqplus_utf8_len(ch);
|
||||
|
||||
if( l<1 ) return -1;
|
||||
int wc = l>1 ? (ch&(0x7F>>l)) : ch;
|
||||
while( l>1 ){
|
||||
wc = (wc<<6) + (*++string & 0x3F);
|
||||
l--;
|
||||
}
|
||||
*result = wc;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Convert one Unicode point to UTF8 encoded version.
|
||||
// Checks if output fits in 1/4/6 bytes buffer.
|
||||
int sqplus_wchar_to_utf8(char *s, int wc, int size){
|
||||
if( size<1 ) return -1;
|
||||
if( (unsigned int)wc>=0x80000000 ) return -2;
|
||||
|
||||
// Single byte case
|
||||
if( wc<0x80 ){
|
||||
*s = (char)wc;
|
||||
//*s = (char)wc&0x7F;
|
||||
return 1;
|
||||
}
|
||||
if( size<4 ) return -3;
|
||||
|
||||
// Two or more UTF8 bytes
|
||||
int p = 1; // Index of last UTF8 byte
|
||||
if( wc>0x7FF ){ // 11 bits
|
||||
// Three or more UTF8 bytes
|
||||
p++; // p>=2
|
||||
if( wc>0xFFFF ){ // 16 bits
|
||||
// Four or more UTF8 bytes
|
||||
p++; // p>=3
|
||||
if( wc>0x1FFFFF ){ // 21 bits
|
||||
// Five or more UTF8 bytes
|
||||
if( size<6 ) return -3;
|
||||
p++; // p>=4 UTF8 bytes
|
||||
if( wc>0x3FFFFFF ){ // 26 bits
|
||||
// Six UTF8 bytes
|
||||
p++; // p>=5
|
||||
if( (unsigned int)wc>(unsigned int)0x7FFFFFF ){ // 31 bits
|
||||
// Would need 7 UTF8 bytes. Not supported.
|
||||
return -10;
|
||||
}
|
||||
s[p-4] = 0x80 | ((wc>>24)&0x3F); // Bit 24..29
|
||||
}
|
||||
s[p-3] = 0x80 | ((wc>>18)&0x3F); // Bit 18..23
|
||||
}
|
||||
s[p-2] = 0x80 | ((wc>>12)&0x3F); // Bit 12..17
|
||||
}
|
||||
s[p-1] = 0x80 | ((wc>>6)&0x3F); // Bit 6..11
|
||||
}
|
||||
s[p] = 0x80 | (wc&0x3F); // Bit 0..5
|
||||
s[0] = (0xFC << (5-p)) | (wc>>(p*6));
|
||||
|
||||
return p+1;
|
||||
}
|
||||
|
||||
#endif // #if !defined(SQPLUS_USE_LATIN1) || SQPLUS_USE_LATIN1==0
|
||||
|
@ -1,15 +1,15 @@
|
||||
#ifndef SQPLUSUTF8_H
|
||||
#define SQPLUSUTF8_H
|
||||
|
||||
#if defined(SQUTF8) || SQPLUS_USE_LATIN1!=1
|
||||
|
||||
// Simple Unicode <-> UTF8 conversion routines
|
||||
//int sqplus_utf8_len(char lead_byte);
|
||||
int sqplus_utf8_len_first(const char *str);
|
||||
int sqplus_utf8_strlen(const char *str);
|
||||
int sqplus_utf8_to_wchar(int *result, const char *string);
|
||||
int sqplus_wchar_to_utf8(char *s, int wc, int size);
|
||||
|
||||
#endif // defined(SQUTF8) || SQPLUS_USE_LATIN1!=1
|
||||
|
||||
#endif // SQPLUSUTF8_H
|
||||
#ifndef SQPLUSUTF8_H
|
||||
#define SQPLUSUTF8_H
|
||||
|
||||
#if defined(SQUTF8) || SQPLUS_USE_LATIN1!=1
|
||||
|
||||
// Simple Unicode <-> UTF8 conversion routines
|
||||
//int sqplus_utf8_len(char lead_byte);
|
||||
int sqplus_utf8_len_first(const char *str);
|
||||
int sqplus_utf8_strlen(const char *str);
|
||||
int sqplus_utf8_to_wchar(int *result, const char *string);
|
||||
int sqplus_wchar_to_utf8(char *s, int wc, int size);
|
||||
|
||||
#endif // defined(SQUTF8) || SQPLUS_USE_LATIN1!=1
|
||||
|
||||
#endif // SQPLUSUTF8_H
|
@ -1,161 +1,161 @@
|
||||
#include "sqplus.h"
|
||||
|
||||
BOOL CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn)
|
||||
{
|
||||
int n = 0;
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,sn->name,-1);
|
||||
sq_newtable(v);
|
||||
const ScriptClassMemberDecl *members = sn->members;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
const ScriptConstantDecl *consts = sn->constants;
|
||||
const ScriptConstantDecl *c = NULL;
|
||||
n = 0;
|
||||
while(consts[n].name) {
|
||||
c = &consts[n];
|
||||
sq_pushstring(v,c->name,-1);
|
||||
switch(c->type) {
|
||||
case OT_STRING: sq_pushstring(v,c->val.s,-1);break;
|
||||
case OT_INTEGER: sq_pushinteger(v,c->val.i);break;
|
||||
case OT_FLOAT: sq_pushfloat(v,c->val.f);break;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
if(sn->delegate) {
|
||||
const ScriptClassMemberDecl *members = sn->delegate;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
sq_newtable(v);
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_setdelegate(v,-2);
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd)
|
||||
{
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,cd->name,-1);
|
||||
if(cd->base) {
|
||||
sq_pushstring(v,cd->base,-1);
|
||||
if(SQ_FAILED(sq_get(v,-3))) { // Make sure the base exists if specified by cd->base name.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if(SQ_FAILED(sq_newclass(v,cd->base?1:0))) { // Will inherit from base class on stack from sq_get() above.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
// sq_settypetag(v,-1,(unsigned int)cd);
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable : 4311)
|
||||
#endif
|
||||
sq_settypetag(v,-1,reinterpret_cast<SQUserPointer>(cd));
|
||||
const ScriptClassMemberDecl *members = cd->members;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
if (members) {
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
} // if
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateNativeClassInstance(HSQUIRRELVM v,
|
||||
const SQChar *classname,
|
||||
SQUserPointer ud,
|
||||
SQRELEASEHOOK hook)
|
||||
{
|
||||
// If we don't do this, SquirrelVM keeps an old pointer around and this
|
||||
// will be used by SquirrelObject. That crashes when using several VMs.
|
||||
SquirrelVM::Init( v );
|
||||
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,classname,-1);
|
||||
if(SQ_FAILED(sq_rawget(v,-2))){ //Get the class (created with sq_newclass()).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
//sq_pushroottable(v);
|
||||
if(SQ_FAILED(sq_createinstance(v,-1))) {
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef SQ_USE_CLASS_INHERITANCE
|
||||
HSQOBJECT ho;
|
||||
sq_getstackobj(v, -1, &ho); // OT_INSTANCE
|
||||
SquirrelObject instance(ho);
|
||||
SqPlus::PopulateAncestry(v, instance, ud);
|
||||
#endif
|
||||
|
||||
sq_remove(v,-3); //removes the root table
|
||||
sq_remove(v,-2); //removes the class
|
||||
if(SQ_FAILED(sq_setinstanceup(v,-1,ud))) {
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
sq_setreleasehook(v,-1,hook);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create native class instance and leave on stack.
|
||||
BOOL CreateConstructNativeClassInstance(HSQUIRRELVM v,const SQChar * className) {
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,className,-1);
|
||||
if (SQ_FAILED(sq_rawget(v,-2))) { // Get the class (created with sq_newclass()).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
#if 0
|
||||
sq_remove(v,-3); // Remove the root table.
|
||||
sq_push(v,1); // Push the 'this'.
|
||||
#else // Kamaitati's change. 5/28/06 jcs.
|
||||
sq_remove(v,-2); // Remove the root table.
|
||||
sq_pushroottable(v); // Push the 'this'.
|
||||
#endif
|
||||
if (SQ_FAILED(sq_call(v,1,SQTrue,SQ_CALL_RAISE_ERROR))) { // Call ClassName(): creates new instance and calls constructor (instead of sq_createinstance() where constructor is not called).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
sq_remove(v,-2); // Remove the class.
|
||||
// int newtop = sq_gettop(v);
|
||||
return TRUE;
|
||||
} // CreateConstructNativeClassInstance
|
||||
|
||||
|
||||
#include "sqplus.h"
|
||||
|
||||
BOOL CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn)
|
||||
{
|
||||
int n = 0;
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,sn->name,-1);
|
||||
sq_newtable(v);
|
||||
const ScriptClassMemberDecl *members = sn->members;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
const ScriptConstantDecl *consts = sn->constants;
|
||||
const ScriptConstantDecl *c = NULL;
|
||||
n = 0;
|
||||
while(consts[n].name) {
|
||||
c = &consts[n];
|
||||
sq_pushstring(v,c->name,-1);
|
||||
switch(c->type) {
|
||||
case OT_STRING: sq_pushstring(v,c->val.s,-1);break;
|
||||
case OT_INTEGER: sq_pushinteger(v,c->val.i);break;
|
||||
case OT_FLOAT: sq_pushfloat(v,c->val.f);break;
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
if(sn->delegate) {
|
||||
const ScriptClassMemberDecl *members = sn->delegate;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
sq_newtable(v);
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
sq_setdelegate(v,-2);
|
||||
}
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd)
|
||||
{
|
||||
int n = 0;
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,cd->name,-1);
|
||||
if(cd->base) {
|
||||
sq_pushstring(v,cd->base,-1);
|
||||
if(SQ_FAILED(sq_get(v,-3))) { // Make sure the base exists if specified by cd->base name.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if(SQ_FAILED(sq_newclass(v,cd->base?1:0))) { // Will inherit from base class on stack from sq_get() above.
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
// sq_settypetag(v,-1,(unsigned int)cd);
|
||||
#ifdef _WIN32
|
||||
#pragma warning(disable : 4311)
|
||||
#endif
|
||||
sq_settypetag(v,-1,reinterpret_cast<SQUserPointer>(cd));
|
||||
const ScriptClassMemberDecl *members = cd->members;
|
||||
const ScriptClassMemberDecl *m = NULL;
|
||||
if (members) {
|
||||
while(members[n].name) {
|
||||
m = &members[n];
|
||||
sq_pushstring(v,m->name,-1);
|
||||
sq_newclosure(v,m->func,0);
|
||||
sq_setparamscheck(v,m->params,m->typemask);
|
||||
sq_setnativeclosurename(v,-1,m->name);
|
||||
sq_createslot(v,-3);
|
||||
n++;
|
||||
}
|
||||
} // if
|
||||
sq_createslot(v,-3);
|
||||
sq_pop(v,1);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateNativeClassInstance(HSQUIRRELVM v,
|
||||
const SQChar *classname,
|
||||
SQUserPointer ud,
|
||||
SQRELEASEHOOK hook)
|
||||
{
|
||||
// If we don't do this, SquirrelVM keeps an old pointer around and this
|
||||
// will be used by SquirrelObject. That crashes when using several VMs.
|
||||
SquirrelVM::Init( v );
|
||||
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,classname,-1);
|
||||
if(SQ_FAILED(sq_rawget(v,-2))){ //Get the class (created with sq_newclass()).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
//sq_pushroottable(v);
|
||||
if(SQ_FAILED(sq_createinstance(v,-1))) {
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef SQ_USE_CLASS_INHERITANCE
|
||||
HSQOBJECT ho;
|
||||
sq_getstackobj(v, -1, &ho); // OT_INSTANCE
|
||||
SquirrelObject instance(ho);
|
||||
SqPlus::PopulateAncestry(v, instance, ud);
|
||||
#endif
|
||||
|
||||
sq_remove(v,-3); //removes the root table
|
||||
sq_remove(v,-2); //removes the class
|
||||
if(SQ_FAILED(sq_setinstanceup(v,-1,ud))) {
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
}
|
||||
sq_setreleasehook(v,-1,hook);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Create native class instance and leave on stack.
|
||||
BOOL CreateConstructNativeClassInstance(HSQUIRRELVM v,const SQChar * className) {
|
||||
int oldtop = sq_gettop(v);
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v,className,-1);
|
||||
if (SQ_FAILED(sq_rawget(v,-2))) { // Get the class (created with sq_newclass()).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
#if 0
|
||||
sq_remove(v,-3); // Remove the root table.
|
||||
sq_push(v,1); // Push the 'this'.
|
||||
#else // Kamaitati's change. 5/28/06 jcs.
|
||||
sq_remove(v,-2); // Remove the root table.
|
||||
sq_pushroottable(v); // Push the 'this'.
|
||||
#endif
|
||||
if (SQ_FAILED(sq_call(v,1,SQTrue,SQ_CALL_RAISE_ERROR))) { // Call ClassName(): creates new instance and calls constructor (instead of sq_createinstance() where constructor is not called).
|
||||
sq_settop(v,oldtop);
|
||||
return FALSE;
|
||||
} // if
|
||||
sq_remove(v,-2); // Remove the class.
|
||||
// int newtop = sq_gettop(v);
|
||||
return TRUE;
|
||||
} // CreateConstructNativeClassInstance
|
||||
|
||||
|
@ -1,152 +1,152 @@
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_H
|
||||
#define SQUIRREL_BINDINGS_UTILS_H
|
||||
|
||||
struct ScriptClassMemberDecl {
|
||||
const SQChar *name;
|
||||
SQFUNCTION func;
|
||||
int params;
|
||||
const SQChar *typemask;
|
||||
};
|
||||
|
||||
struct SquirrelClassDecl {
|
||||
const SQChar *name;
|
||||
const SQChar *base;
|
||||
const ScriptClassMemberDecl *members;
|
||||
};
|
||||
|
||||
struct ScriptConstantDecl {
|
||||
const SQChar *name;
|
||||
SQObjectType type;
|
||||
union value {
|
||||
value(float v){ f = v; }
|
||||
value(int v){ i = v; }
|
||||
value(long int v){ li = v; }
|
||||
value(const SQChar *v){ s = v; }
|
||||
float f;
|
||||
int i;
|
||||
long int li;
|
||||
const SQChar *s;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct ScriptNamespaceDecl {
|
||||
const SQChar *name;
|
||||
const ScriptClassMemberDecl *members;
|
||||
const ScriptConstantDecl *constants;
|
||||
const ScriptClassMemberDecl *delegate;
|
||||
};
|
||||
|
||||
#define _BEGIN_CLASS(classname) \
|
||||
int __##classname##__typeof(HSQUIRRELVM v) \
|
||||
{ \
|
||||
sq_pushstring(v,_SC(#classname),-1); \
|
||||
return 1; \
|
||||
} \
|
||||
struct ScriptClassMemberDecl __##classname##_members[] = { \
|
||||
{_SC("_typeof"),__##classname##__typeof,1,NULL},
|
||||
|
||||
#define _BEGIN_NAMESPACE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_members[] = {
|
||||
#define _BEGIN_NAMESPACE_CONSTANTS(xnamespace) {NULL,NULL,0,NULL}}; \
|
||||
struct ScriptConstantDecl __##xnamespace##_constants[] = {
|
||||
|
||||
#define _BEGIN_DELEGATE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_delegate[] = {
|
||||
#define _DELEGATE(xnamespace) __##xnamespace##_delegate
|
||||
#define _END_DELEGATE(classname) {NULL,NULL,NULL,NULL}};
|
||||
|
||||
#define _CONSTANT(name,type,val) {_SC(#name),type,val},
|
||||
#define _CONSTANT_IMPL(name,type) {_SC(#name),type,name},
|
||||
|
||||
#define _MEMBER_FUNCTION(classname,name,nparams,typemask) \
|
||||
{_SC(#name),__##classname##_##name,nparams,typemask},
|
||||
|
||||
#define _END_NAMESPACE(classname,delegate) {NULL,OT_NULL,0}}; \
|
||||
struct ScriptNamespaceDecl __##classname##_decl = { \
|
||||
_SC(#classname), __##classname##_members,__##classname##_constants,delegate };
|
||||
|
||||
#define _END_CLASS(classname) {NULL,NULL,0,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), NULL, __##classname##_members };
|
||||
|
||||
|
||||
#define _END_CLASS_INHERITANCE(classname,base) {NULL,NULL,NULL,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), _SC(#base), __##classname##_members };
|
||||
|
||||
#define _MEMBER_FUNCTION_IMPL(classname,name) \
|
||||
int __##classname##_##name(HSQUIRRELVM v)
|
||||
|
||||
#define _INIT_STATIC_NAMESPACE(classname) CreateStaticNamespace(SquirrelVM::GetVMPtr(),&__##classname##_decl);
|
||||
#define _INIT_CLASS(classname)CreateClass(SquirrelVM::GetVMPtr(),&__##classname##_decl);
|
||||
|
||||
#define _DECL_STATIC_NAMESPACE(xnamespace) extern struct ScriptNamespaceDecl __##xnamespace##_decl;
|
||||
#define _DECL_CLASS(classname) extern struct SquirrelClassDecl __##classname##_decl;
|
||||
|
||||
#define _CHECK_SELF(cppclass,scriptclass) \
|
||||
cppclass *self = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
return sq_throwerror(v,_SC("invalid instance type"));\
|
||||
}
|
||||
|
||||
#define _CHECK_INST_PARAM(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
return sq_throwerror(v,_SC("invalid instance type"));\
|
||||
} \
|
||||
|
||||
#define _CHECK_INST_PARAM_BREAK(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
break; \
|
||||
} \
|
||||
|
||||
#define _CLASS_TAG(classname) ((unsigned int)&__##classname##_decl)
|
||||
|
||||
|
||||
#define _DECL_NATIVE_CONSTRUCTION(classname,cppclass) \
|
||||
BOOL push_##classname(cppclass &quat); \
|
||||
SquirrelObject new_##classname(cppclass &quat);
|
||||
|
||||
#define _IMPL_NATIVE_CONSTRUCTION(classname,cppclass) \
|
||||
static int classname##_release_hook(SQUserPointer p, int size) \
|
||||
{ \
|
||||
if(p) { \
|
||||
cppclass *pv = (cppclass *)p; \
|
||||
delete pv; \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
BOOL push_##classname(cppclass &quat) \
|
||||
{ \
|
||||
cppclass *newquat = new cppclass; \
|
||||
*newquat = quat; \
|
||||
if(!CreateNativeClassInstance(SquirrelVM::GetVMPtr(),_SC(#classname),newquat,classname##_release_hook)) { \
|
||||
delete newquat; \
|
||||
return FALSE; \
|
||||
} \
|
||||
return TRUE; \
|
||||
} \
|
||||
SquirrelObject new_##classname(cppclass &quat) \
|
||||
{ \
|
||||
SquirrelObject ret; \
|
||||
if(push_##classname(quat)) { \
|
||||
ret.AttachToStackObject(-1); \
|
||||
sq_pop(SquirrelVM::GetVMPtr(),1); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
int construct_##classname(cppclass *p) \
|
||||
{ \
|
||||
sq_setinstanceup(SquirrelVM::GetVMPtr(),1,p); \
|
||||
sq_setreleasehook(SquirrelVM::GetVMPtr(),1,classname##_release_hook); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
BOOL CreateStaticClass(HSQUIRRELVM v,SquirrelClassDecl *cd);
|
||||
BOOL CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn);
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd);
|
||||
BOOL InitScriptClasses(HSQUIRRELVM v);
|
||||
BOOL CreateNativeClassInstance(HSQUIRRELVM v,const SQChar *classname,SQUserPointer ud,SQRELEASEHOOK hook);
|
||||
BOOL CreateConstructNativeClassInstance(HSQUIRRELVM v,const SQChar * className);
|
||||
|
||||
#endif // SQUIRREL_BINDINGS_UTILS_H
|
||||
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_H
|
||||
#define SQUIRREL_BINDINGS_UTILS_H
|
||||
|
||||
struct ScriptClassMemberDecl {
|
||||
const SQChar *name;
|
||||
SQFUNCTION func;
|
||||
int params;
|
||||
const SQChar *typemask;
|
||||
};
|
||||
|
||||
struct SquirrelClassDecl {
|
||||
const SQChar *name;
|
||||
const SQChar *base;
|
||||
const ScriptClassMemberDecl *members;
|
||||
};
|
||||
|
||||
struct ScriptConstantDecl {
|
||||
const SQChar *name;
|
||||
SQObjectType type;
|
||||
union value {
|
||||
value(float v){ f = v; }
|
||||
value(int v){ i = v; }
|
||||
value(long int v){ li = v; }
|
||||
value(const SQChar *v){ s = v; }
|
||||
float f;
|
||||
int i;
|
||||
long int li;
|
||||
const SQChar *s;
|
||||
} val;
|
||||
};
|
||||
|
||||
struct ScriptNamespaceDecl {
|
||||
const SQChar *name;
|
||||
const ScriptClassMemberDecl *members;
|
||||
const ScriptConstantDecl *constants;
|
||||
const ScriptClassMemberDecl *delegate;
|
||||
};
|
||||
|
||||
#define _BEGIN_CLASS(classname) \
|
||||
int __##classname##__typeof(HSQUIRRELVM v) \
|
||||
{ \
|
||||
sq_pushstring(v,_SC(#classname),-1); \
|
||||
return 1; \
|
||||
} \
|
||||
struct ScriptClassMemberDecl __##classname##_members[] = { \
|
||||
{_SC("_typeof"),__##classname##__typeof,1,NULL},
|
||||
|
||||
#define _BEGIN_NAMESPACE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_members[] = {
|
||||
#define _BEGIN_NAMESPACE_CONSTANTS(xnamespace) {NULL,NULL,0,NULL}}; \
|
||||
struct ScriptConstantDecl __##xnamespace##_constants[] = {
|
||||
|
||||
#define _BEGIN_DELEGATE(xnamespace) struct ScriptClassMemberDecl __##xnamespace##_delegate[] = {
|
||||
#define _DELEGATE(xnamespace) __##xnamespace##_delegate
|
||||
#define _END_DELEGATE(classname) {NULL,NULL,NULL,NULL}};
|
||||
|
||||
#define _CONSTANT(name,type,val) {_SC(#name),type,val},
|
||||
#define _CONSTANT_IMPL(name,type) {_SC(#name),type,name},
|
||||
|
||||
#define _MEMBER_FUNCTION(classname,name,nparams,typemask) \
|
||||
{_SC(#name),__##classname##_##name,nparams,typemask},
|
||||
|
||||
#define _END_NAMESPACE(classname,delegate) {NULL,OT_NULL,0}}; \
|
||||
struct ScriptNamespaceDecl __##classname##_decl = { \
|
||||
_SC(#classname), __##classname##_members,__##classname##_constants,delegate };
|
||||
|
||||
#define _END_CLASS(classname) {NULL,NULL,0,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), NULL, __##classname##_members };
|
||||
|
||||
|
||||
#define _END_CLASS_INHERITANCE(classname,base) {NULL,NULL,NULL,NULL}}; \
|
||||
struct SquirrelClassDecl __##classname##_decl = { \
|
||||
_SC(#classname), _SC(#base), __##classname##_members };
|
||||
|
||||
#define _MEMBER_FUNCTION_IMPL(classname,name) \
|
||||
int __##classname##_##name(HSQUIRRELVM v)
|
||||
|
||||
#define _INIT_STATIC_NAMESPACE(classname) CreateStaticNamespace(SquirrelVM::GetVMPtr(),&__##classname##_decl);
|
||||
#define _INIT_CLASS(classname)CreateClass(SquirrelVM::GetVMPtr(),&__##classname##_decl);
|
||||
|
||||
#define _DECL_STATIC_NAMESPACE(xnamespace) extern struct ScriptNamespaceDecl __##xnamespace##_decl;
|
||||
#define _DECL_CLASS(classname) extern struct SquirrelClassDecl __##classname##_decl;
|
||||
|
||||
#define _CHECK_SELF(cppclass,scriptclass) \
|
||||
cppclass *self = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,1,(SQUserPointer*)&self,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
return sq_throwerror(v,_SC("invalid instance type"));\
|
||||
}
|
||||
|
||||
#define _CHECK_INST_PARAM(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
return sq_throwerror(v,_SC("invalid instance type"));\
|
||||
} \
|
||||
|
||||
#define _CHECK_INST_PARAM_BREAK(pname,idx,cppclass,scriptclass) \
|
||||
cppclass *pname = NULL; \
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&pname,(SQUserPointer)&__##scriptclass##_decl))) { \
|
||||
break; \
|
||||
} \
|
||||
|
||||
#define _CLASS_TAG(classname) ((unsigned int)&__##classname##_decl)
|
||||
|
||||
|
||||
#define _DECL_NATIVE_CONSTRUCTION(classname,cppclass) \
|
||||
BOOL push_##classname(cppclass &quat); \
|
||||
SquirrelObject new_##classname(cppclass &quat);
|
||||
|
||||
#define _IMPL_NATIVE_CONSTRUCTION(classname,cppclass) \
|
||||
static int classname##_release_hook(SQUserPointer p, int size) \
|
||||
{ \
|
||||
if(p) { \
|
||||
cppclass *pv = (cppclass *)p; \
|
||||
delete pv; \
|
||||
} \
|
||||
return 0; \
|
||||
} \
|
||||
BOOL push_##classname(cppclass &quat) \
|
||||
{ \
|
||||
cppclass *newquat = new cppclass; \
|
||||
*newquat = quat; \
|
||||
if(!CreateNativeClassInstance(SquirrelVM::GetVMPtr(),_SC(#classname),newquat,classname##_release_hook)) { \
|
||||
delete newquat; \
|
||||
return FALSE; \
|
||||
} \
|
||||
return TRUE; \
|
||||
} \
|
||||
SquirrelObject new_##classname(cppclass &quat) \
|
||||
{ \
|
||||
SquirrelObject ret; \
|
||||
if(push_##classname(quat)) { \
|
||||
ret.AttachToStackObject(-1); \
|
||||
sq_pop(SquirrelVM::GetVMPtr(),1); \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
int construct_##classname(cppclass *p) \
|
||||
{ \
|
||||
sq_setinstanceup(SquirrelVM::GetVMPtr(),1,p); \
|
||||
sq_setreleasehook(SquirrelVM::GetVMPtr(),1,classname##_release_hook); \
|
||||
return 1; \
|
||||
}
|
||||
|
||||
BOOL CreateStaticClass(HSQUIRRELVM v,SquirrelClassDecl *cd);
|
||||
BOOL CreateStaticNamespace(HSQUIRRELVM v,ScriptNamespaceDecl *sn);
|
||||
BOOL CreateClass(HSQUIRRELVM v,SquirrelClassDecl *cd);
|
||||
BOOL InitScriptClasses(HSQUIRRELVM v);
|
||||
BOOL CreateNativeClassInstance(HSQUIRRELVM v,const SQChar *classname,SQUserPointer ud,SQRELEASEHOOK hook);
|
||||
BOOL CreateConstructNativeClassInstance(HSQUIRRELVM v,const SQChar * className);
|
||||
|
||||
#endif // SQUIRREL_BINDINGS_UTILS_H
|
||||
|
@ -1,31 +1,31 @@
|
||||
#include "sqplus.h"
|
||||
|
||||
//#include "SquirrelObject.h"
|
||||
//#include "SquirrelVM.h"
|
||||
#include "SquirrelBindingsUtilsWin32.h"
|
||||
|
||||
int refcounted_release_hook(SQUserPointer p, int size)
|
||||
{
|
||||
IUnknown *pRC = (IUnknown*)p;
|
||||
pRC->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOL __CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC,SQRELEASEHOOK hook)
|
||||
{
|
||||
if(!CreateNativeClassInstance(v,classname,pRC,hook)) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int construct_RefCounted(IUnknown *p)
|
||||
{
|
||||
sq_setinstanceup(SquirrelVM::GetVMPtr(),1,p);
|
||||
sq_setreleasehook(SquirrelVM::GetVMPtr(),1,refcounted_release_hook);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
BOOL CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC)
|
||||
{
|
||||
return __CreateRefCountedInstance(v,classname,pRC,refcounted_release_hook);
|
||||
}
|
||||
#include "sqplus.h"
|
||||
|
||||
//#include "SquirrelObject.h"
|
||||
//#include "SquirrelVM.h"
|
||||
#include "SquirrelBindingsUtilsWin32.h"
|
||||
|
||||
int refcounted_release_hook(SQUserPointer p, int size)
|
||||
{
|
||||
IUnknown *pRC = (IUnknown*)p;
|
||||
pRC->Release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static BOOL __CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC,SQRELEASEHOOK hook)
|
||||
{
|
||||
if(!CreateNativeClassInstance(v,classname,pRC,hook)) return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int construct_RefCounted(IUnknown *p)
|
||||
{
|
||||
sq_setinstanceup(SquirrelVM::GetVMPtr(),1,p);
|
||||
sq_setreleasehook(SquirrelVM::GetVMPtr(),1,refcounted_release_hook);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
BOOL CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC)
|
||||
{
|
||||
return __CreateRefCountedInstance(v,classname,pRC,refcounted_release_hook);
|
||||
}
|
@ -1,41 +1,41 @@
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
#define SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
|
||||
#ifndef _INC_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef __IUnknown_INTERFACE_DEFINED__
|
||||
#include <unknwn.h>
|
||||
#endif
|
||||
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_H
|
||||
#include "SquirrelBindingsUtils.h"
|
||||
#endif
|
||||
|
||||
#define _DECLARE_REFCOUNTED_NEW(cppclass,classname) \
|
||||
SquirrelObject new_##classname(cppclass *ptr) { \
|
||||
if(CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
|
||||
HSQOBJECT o; \
|
||||
sq_getstackobj(SquirrelVM::GetVMPtr(),-1,&o); \
|
||||
SquirrelObject tmp = o; \
|
||||
sq_pop(SquirrelVM::GetVMPtr(),1); \
|
||||
return tmp; \
|
||||
} \
|
||||
return SquirrelObject() ; \
|
||||
}
|
||||
|
||||
#define _RETURN_REFCOUNTED_INSTANCE(classname,ptr) \
|
||||
if(!CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
|
||||
return sa.ThrowError(_SC("cannot create the class instance")); \
|
||||
} \
|
||||
return 1;
|
||||
|
||||
BOOL CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
|
||||
BOOL CreateRefCountedInstanceChached(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
|
||||
int refcounted_release_hook(SQUserPointer p, int size);
|
||||
int construct_RefCounted(IUnknown *p);
|
||||
|
||||
#endif // SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
#define SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
|
||||
#ifndef _INC_WINDOWS
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
// Windows Header Files:
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#ifndef __IUnknown_INTERFACE_DEFINED__
|
||||
#include <unknwn.h>
|
||||
#endif
|
||||
|
||||
#ifndef SQUIRREL_BINDINGS_UTILS_H
|
||||
#include "SquirrelBindingsUtils.h"
|
||||
#endif
|
||||
|
||||
#define _DECLARE_REFCOUNTED_NEW(cppclass,classname) \
|
||||
SquirrelObject new_##classname(cppclass *ptr) { \
|
||||
if(CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
|
||||
HSQOBJECT o; \
|
||||
sq_getstackobj(SquirrelVM::GetVMPtr(),-1,&o); \
|
||||
SquirrelObject tmp = o; \
|
||||
sq_pop(SquirrelVM::GetVMPtr(),1); \
|
||||
return tmp; \
|
||||
} \
|
||||
return SquirrelObject() ; \
|
||||
}
|
||||
|
||||
#define _RETURN_REFCOUNTED_INSTANCE(classname,ptr) \
|
||||
if(!CreateRefCountedInstance(SquirrelVM::GetVMPtr(),_SC(#classname),ptr)) { \
|
||||
return sa.ThrowError(_SC("cannot create the class instance")); \
|
||||
} \
|
||||
return 1;
|
||||
|
||||
BOOL CreateRefCountedInstance(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
|
||||
BOOL CreateRefCountedInstanceChached(HSQUIRRELVM v,const SQChar *classname,IUnknown *pRC);
|
||||
int refcounted_release_hook(SQUserPointer p, int size);
|
||||
int construct_RefCounted(IUnknown *p);
|
||||
|
||||
#endif // SQUIRREL_BINDINGS_UTILS_WIN32_H
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,256 +1,256 @@
|
||||
#ifndef _SQUIRREL_OBJECT_H_
|
||||
#define _SQUIRREL_OBJECT_H_
|
||||
|
||||
class SquirrelObject
|
||||
{
|
||||
friend class SquirrelVM;
|
||||
|
||||
public:
|
||||
SquirrelObject();
|
||||
virtual ~SquirrelObject();
|
||||
SquirrelObject(const SquirrelObject & o);
|
||||
SquirrelObject(HSQOBJECT o);
|
||||
|
||||
#if 1
|
||||
template <typename _ty>
|
||||
SquirrelObject(const _ty & val) { sq_resetobject(&_o); Set((_ty &)val); } // Cast away const to avoid compiler SqPlus::Push() match issue.
|
||||
template <typename _ty>
|
||||
SquirrelObject(_ty & val) { sq_resetobject(&_o); Set(val); }
|
||||
template <typename _ty>
|
||||
SquirrelObject(_ty * val) { sq_resetobject(&_o); SetByValue(val); } // Set() would also be OK here. SetByValue() to save potential compiler overhead.
|
||||
#endif
|
||||
|
||||
SquirrelObject & operator = (HSQOBJECT ho);
|
||||
SquirrelObject & operator = (const SquirrelObject &o);
|
||||
SquirrelObject & operator = (int n);
|
||||
SquirrelObject & operator = (HSQUIRRELVM v);
|
||||
|
||||
operator HSQOBJECT& (){ return _o; }
|
||||
bool operator ==(const SquirrelObject& o);
|
||||
bool CompareUserPointer(const SquirrelObject& o);
|
||||
|
||||
void AttachToStackObject(int idx);
|
||||
void Reset(void); // Release (any) reference and reset _o.
|
||||
SquirrelObject Clone();
|
||||
BOOL SetValue(const SquirrelObject &key,const SquirrelObject &val);
|
||||
|
||||
BOOL SetValue(SQInteger key,const SquirrelObject &val);
|
||||
BOOL SetValue(INT key,bool b); // Compiler treats SQBool as INT.
|
||||
BOOL SetValue(INT key,INT n);
|
||||
BOOL SetValue(INT key,FLOAT f);
|
||||
BOOL SetValue(INT key,const SQChar *s);
|
||||
|
||||
BOOL SetValue(const SQChar *key,const SquirrelObject &val);
|
||||
BOOL SetValue(const SQChar *key,bool b);
|
||||
BOOL SetValue(const SQChar *key,INT n);
|
||||
BOOL SetValue(const SQChar *key,FLOAT f);
|
||||
BOOL SetValue(const SQChar *key,const SQChar *s);
|
||||
|
||||
BOOL SetUserPointer(const SQChar * key,SQUserPointer up);
|
||||
SQUserPointer GetUserPointer(const SQChar * key);
|
||||
BOOL SetUserPointer(INT key,SQUserPointer up);
|
||||
SQUserPointer GetUserPointer(INT key);
|
||||
|
||||
BOOL NewUserData(const SQChar * key,INT size,SQUserPointer * typetag=0);
|
||||
BOOL GetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag=0);
|
||||
BOOL RawGetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag=0);
|
||||
|
||||
// === BEGIN Arrays ===
|
||||
|
||||
BOOL ArrayResize(INT newSize);
|
||||
BOOL ArrayExtend(INT amount);
|
||||
BOOL ArrayReverse(void);
|
||||
SquirrelObject ArrayPop(SQBool returnPoppedVal=SQTrue);
|
||||
|
||||
void ArrayAppend(const SquirrelObject &o);
|
||||
|
||||
template<typename T>
|
||||
BOOL ArrayAppend(T item);
|
||||
|
||||
// === END Arrays ===
|
||||
|
||||
BOOL SetInstanceUP(SQUserPointer up);
|
||||
BOOL IsNull() const;
|
||||
int IsNumeric() const;
|
||||
int Len() const;
|
||||
BOOL SetDelegate(SquirrelObject &obj);
|
||||
SquirrelObject GetDelegate();
|
||||
const SQChar* ToString();
|
||||
bool ToBool();
|
||||
SQInteger ToInteger();
|
||||
SQFloat ToFloat();
|
||||
SQUserPointer GetInstanceUP(SQUserPointer tag) const;
|
||||
SquirrelObject GetValue(const SQChar *key) const;
|
||||
BOOL Exists(const SQChar *key) const;
|
||||
FLOAT GetFloat(const SQChar *key) const;
|
||||
INT GetInt(const SQChar *key) const;
|
||||
const SQChar *GetString(const SQChar *key) const;
|
||||
bool GetBool(const SQChar *key) const;
|
||||
SquirrelObject GetValue(INT key) const;
|
||||
FLOAT GetFloat(INT key) const;
|
||||
INT GetInt(INT key) const;
|
||||
const SQChar *GetString(INT key) const;
|
||||
bool GetBool(INT key) const;
|
||||
SquirrelObject GetAttributes(const SQChar *key = NULL);
|
||||
SQObjectType GetType();
|
||||
HSQOBJECT & GetObjectHandle() const {return *(HSQOBJECT*)&_o;}
|
||||
BOOL BeginIteration();
|
||||
BOOL Next(SquirrelObject &key,SquirrelObject &value);
|
||||
void EndIteration();
|
||||
|
||||
BOOL GetTypeTag(SQUserPointer * typeTag);
|
||||
|
||||
// === Get the type name of item/object through string key in a table or class. Returns NULL if the type name is not set (not an SqPlus registered type).
|
||||
const SQChar * GetTypeName(const SQChar * key);
|
||||
// === Get the type name of item/object through INT key in a table or class. Returns NULL if the type name is not set (not an SqPlus registered type).
|
||||
const SQChar * GetTypeName(INT key);
|
||||
// === Get the type name of this object, else return NULL if not an SqPlus registered type.
|
||||
const SQChar * GetTypeName(void);
|
||||
|
||||
// === Return base class of object using sq_getbase() ===
|
||||
SquirrelObject GetBase();
|
||||
|
||||
// === BEGIN code suggestion from the Wiki ===
|
||||
// Get any bound type from this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
_ty Get(void);
|
||||
|
||||
// Set any bound type to this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
SquirrelObject SetByValue(_ty val); // classes/structs should be passed by ref (below) to avoid an extra copy.
|
||||
|
||||
// Set any bound type to this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
SquirrelObject &Set(_ty & val);
|
||||
|
||||
// === END code suggestion from the Wiki ===
|
||||
|
||||
private:
|
||||
BOOL GetSlot(const SQChar *name) const;
|
||||
BOOL RawGetSlot(const SQChar *name) const;
|
||||
BOOL GetSlot(INT key) const;
|
||||
HSQOBJECT _o;
|
||||
};
|
||||
|
||||
struct StackHandler {
|
||||
StackHandler(HSQUIRRELVM v) {
|
||||
_top = sq_gettop(v);
|
||||
this->v = v;
|
||||
}
|
||||
SQFloat GetFloat(int idx) {
|
||||
SQFloat x = 0.0f;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getfloat(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQInteger GetInt(int idx) {
|
||||
SQInteger x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getinteger(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
HSQOBJECT GetObjectHandle(int idx) {
|
||||
HSQOBJECT x;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_resetobject(&x);
|
||||
sq_getstackobj(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
const SQChar *GetString(int idx)
|
||||
{
|
||||
const SQChar *x = NULL;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getstring(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetUserPointer(int idx)
|
||||
{
|
||||
SQUserPointer x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getuserpointer(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetInstanceUp(int idx,SQUserPointer tag)
|
||||
{
|
||||
SQUserPointer self;
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&self,tag)))
|
||||
return NULL;
|
||||
return self;
|
||||
}
|
||||
SQUserPointer GetUserData(int idx,SQUserPointer tag=0)
|
||||
{
|
||||
SQUserPointer otag;
|
||||
SQUserPointer up;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getuserdata(v,idx,&up,&otag))) {
|
||||
if(tag == otag)
|
||||
return up;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
BOOL GetBool(int idx)
|
||||
{
|
||||
SQBool ret;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getbool(v,idx,&ret)))
|
||||
return ret;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
int GetType(int idx)
|
||||
{
|
||||
if(idx > 0 && idx <= _top) {
|
||||
return sq_gettype(v,idx);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetParamCount() {
|
||||
return _top;
|
||||
}
|
||||
int Return(const SQChar *s)
|
||||
{
|
||||
sq_pushstring(v,s,-1);
|
||||
return 1;
|
||||
}
|
||||
int Return(FLOAT f)
|
||||
{
|
||||
sq_pushfloat(v,f);
|
||||
return 1;
|
||||
}
|
||||
int Return(INT i)
|
||||
{
|
||||
sq_pushinteger(v,i);
|
||||
return 1;
|
||||
}
|
||||
int Return(bool b)
|
||||
{
|
||||
sq_pushbool(v,b);
|
||||
return 1;
|
||||
}
|
||||
int Return(SQUserPointer p) {
|
||||
sq_pushuserpointer(v,p);
|
||||
return 1;
|
||||
}
|
||||
int Return(SquirrelObject &o)
|
||||
{
|
||||
sq_pushobject(v,o.GetObjectHandle());
|
||||
return 1;
|
||||
}
|
||||
int Return() { return 0; }
|
||||
int ThrowError(const SQChar *error) {
|
||||
return sq_throwerror(v,error);
|
||||
}
|
||||
HSQUIRRELVM GetVMPtr() { return v; }
|
||||
private:
|
||||
int _top;
|
||||
HSQUIRRELVM v;
|
||||
};
|
||||
|
||||
#endif //_SQUIRREL_OBJECT_H_
|
||||
#ifndef _SQUIRREL_OBJECT_H_
|
||||
#define _SQUIRREL_OBJECT_H_
|
||||
|
||||
class SquirrelObject
|
||||
{
|
||||
friend class SquirrelVM;
|
||||
|
||||
public:
|
||||
SquirrelObject();
|
||||
virtual ~SquirrelObject();
|
||||
SquirrelObject(const SquirrelObject & o);
|
||||
SquirrelObject(HSQOBJECT o);
|
||||
|
||||
#if 1
|
||||
template <typename _ty>
|
||||
SquirrelObject(const _ty & val) { sq_resetobject(&_o); Set((_ty &)val); } // Cast away const to avoid compiler SqPlus::Push() match issue.
|
||||
template <typename _ty>
|
||||
SquirrelObject(_ty & val) { sq_resetobject(&_o); Set(val); }
|
||||
template <typename _ty>
|
||||
SquirrelObject(_ty * val) { sq_resetobject(&_o); SetByValue(val); } // Set() would also be OK here. SetByValue() to save potential compiler overhead.
|
||||
#endif
|
||||
|
||||
SquirrelObject & operator = (HSQOBJECT ho);
|
||||
SquirrelObject & operator = (const SquirrelObject &o);
|
||||
SquirrelObject & operator = (int n);
|
||||
SquirrelObject & operator = (HSQUIRRELVM v);
|
||||
|
||||
operator HSQOBJECT& (){ return _o; }
|
||||
bool operator ==(const SquirrelObject& o);
|
||||
bool CompareUserPointer(const SquirrelObject& o);
|
||||
|
||||
void AttachToStackObject(int idx);
|
||||
void Reset(void); // Release (any) reference and reset _o.
|
||||
SquirrelObject Clone();
|
||||
BOOL SetValue(const SquirrelObject &key,const SquirrelObject &val);
|
||||
|
||||
BOOL SetValue(SQInteger key,const SquirrelObject &val);
|
||||
BOOL SetValue(INT key,bool b); // Compiler treats SQBool as INT.
|
||||
BOOL SetValue(INT key,INT n);
|
||||
BOOL SetValue(INT key,FLOAT f);
|
||||
BOOL SetValue(INT key,const SQChar *s);
|
||||
|
||||
BOOL SetValue(const SQChar *key,const SquirrelObject &val);
|
||||
BOOL SetValue(const SQChar *key,bool b);
|
||||
BOOL SetValue(const SQChar *key,INT n);
|
||||
BOOL SetValue(const SQChar *key,FLOAT f);
|
||||
BOOL SetValue(const SQChar *key,const SQChar *s);
|
||||
|
||||
BOOL SetUserPointer(const SQChar * key,SQUserPointer up);
|
||||
SQUserPointer GetUserPointer(const SQChar * key);
|
||||
BOOL SetUserPointer(INT key,SQUserPointer up);
|
||||
SQUserPointer GetUserPointer(INT key);
|
||||
|
||||
BOOL NewUserData(const SQChar * key,INT size,SQUserPointer * typetag=0);
|
||||
BOOL GetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag=0);
|
||||
BOOL RawGetUserData(const SQChar * key,SQUserPointer * data,SQUserPointer * typetag=0);
|
||||
|
||||
// === BEGIN Arrays ===
|
||||
|
||||
BOOL ArrayResize(INT newSize);
|
||||
BOOL ArrayExtend(INT amount);
|
||||
BOOL ArrayReverse(void);
|
||||
SquirrelObject ArrayPop(SQBool returnPoppedVal=SQTrue);
|
||||
|
||||
void ArrayAppend(const SquirrelObject &o);
|
||||
|
||||
template<typename T>
|
||||
BOOL ArrayAppend(T item);
|
||||
|
||||
// === END Arrays ===
|
||||
|
||||
BOOL SetInstanceUP(SQUserPointer up);
|
||||
BOOL IsNull() const;
|
||||
int IsNumeric() const;
|
||||
int Len() const;
|
||||
BOOL SetDelegate(SquirrelObject &obj);
|
||||
SquirrelObject GetDelegate();
|
||||
const SQChar* ToString();
|
||||
bool ToBool();
|
||||
SQInteger ToInteger();
|
||||
SQFloat ToFloat();
|
||||
SQUserPointer GetInstanceUP(SQUserPointer tag) const;
|
||||
SquirrelObject GetValue(const SQChar *key) const;
|
||||
BOOL Exists(const SQChar *key) const;
|
||||
FLOAT GetFloat(const SQChar *key) const;
|
||||
INT GetInt(const SQChar *key) const;
|
||||
const SQChar *GetString(const SQChar *key) const;
|
||||
bool GetBool(const SQChar *key) const;
|
||||
SquirrelObject GetValue(INT key) const;
|
||||
FLOAT GetFloat(INT key) const;
|
||||
INT GetInt(INT key) const;
|
||||
const SQChar *GetString(INT key) const;
|
||||
bool GetBool(INT key) const;
|
||||
SquirrelObject GetAttributes(const SQChar *key = NULL);
|
||||
SQObjectType GetType();
|
||||
HSQOBJECT & GetObjectHandle() const {return *(HSQOBJECT*)&_o;}
|
||||
BOOL BeginIteration();
|
||||
BOOL Next(SquirrelObject &key,SquirrelObject &value);
|
||||
void EndIteration();
|
||||
|
||||
BOOL GetTypeTag(SQUserPointer * typeTag);
|
||||
|
||||
// === Get the type name of item/object through string key in a table or class. Returns NULL if the type name is not set (not an SqPlus registered type).
|
||||
const SQChar * GetTypeName(const SQChar * key);
|
||||
// === Get the type name of item/object through INT key in a table or class. Returns NULL if the type name is not set (not an SqPlus registered type).
|
||||
const SQChar * GetTypeName(INT key);
|
||||
// === Get the type name of this object, else return NULL if not an SqPlus registered type.
|
||||
const SQChar * GetTypeName(void);
|
||||
|
||||
// === Return base class of object using sq_getbase() ===
|
||||
SquirrelObject GetBase();
|
||||
|
||||
// === BEGIN code suggestion from the Wiki ===
|
||||
// Get any bound type from this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
_ty Get(void);
|
||||
|
||||
// Set any bound type to this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
SquirrelObject SetByValue(_ty val); // classes/structs should be passed by ref (below) to avoid an extra copy.
|
||||
|
||||
// Set any bound type to this SquirrelObject. Note that Squirrel's handling of references and pointers still holds here.
|
||||
template<typename _ty>
|
||||
SquirrelObject &Set(_ty & val);
|
||||
|
||||
// === END code suggestion from the Wiki ===
|
||||
|
||||
private:
|
||||
BOOL GetSlot(const SQChar *name) const;
|
||||
BOOL RawGetSlot(const SQChar *name) const;
|
||||
BOOL GetSlot(INT key) const;
|
||||
HSQOBJECT _o;
|
||||
};
|
||||
|
||||
struct StackHandler {
|
||||
StackHandler(HSQUIRRELVM v) {
|
||||
_top = sq_gettop(v);
|
||||
this->v = v;
|
||||
}
|
||||
SQFloat GetFloat(int idx) {
|
||||
SQFloat x = 0.0f;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getfloat(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQInteger GetInt(int idx) {
|
||||
SQInteger x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getinteger(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
HSQOBJECT GetObjectHandle(int idx) {
|
||||
HSQOBJECT x;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_resetobject(&x);
|
||||
sq_getstackobj(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
const SQChar *GetString(int idx)
|
||||
{
|
||||
const SQChar *x = NULL;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getstring(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetUserPointer(int idx)
|
||||
{
|
||||
SQUserPointer x = 0;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
sq_getuserpointer(v,idx,&x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
SQUserPointer GetInstanceUp(int idx,SQUserPointer tag)
|
||||
{
|
||||
SQUserPointer self;
|
||||
if(SQ_FAILED(sq_getinstanceup(v,idx,(SQUserPointer*)&self,tag)))
|
||||
return NULL;
|
||||
return self;
|
||||
}
|
||||
SQUserPointer GetUserData(int idx,SQUserPointer tag=0)
|
||||
{
|
||||
SQUserPointer otag;
|
||||
SQUserPointer up;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getuserdata(v,idx,&up,&otag))) {
|
||||
if(tag == otag)
|
||||
return up;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
BOOL GetBool(int idx)
|
||||
{
|
||||
SQBool ret;
|
||||
if(idx > 0 && idx <= _top) {
|
||||
if(SQ_SUCCEEDED(sq_getbool(v,idx,&ret)))
|
||||
return ret;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
int GetType(int idx)
|
||||
{
|
||||
if(idx > 0 && idx <= _top) {
|
||||
return sq_gettype(v,idx);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int GetParamCount() {
|
||||
return _top;
|
||||
}
|
||||
int Return(const SQChar *s)
|
||||
{
|
||||
sq_pushstring(v,s,-1);
|
||||
return 1;
|
||||
}
|
||||
int Return(FLOAT f)
|
||||
{
|
||||
sq_pushfloat(v,f);
|
||||
return 1;
|
||||
}
|
||||
int Return(INT i)
|
||||
{
|
||||
sq_pushinteger(v,i);
|
||||
return 1;
|
||||
}
|
||||
int Return(bool b)
|
||||
{
|
||||
sq_pushbool(v,b);
|
||||
return 1;
|
||||
}
|
||||
int Return(SQUserPointer p) {
|
||||
sq_pushuserpointer(v,p);
|
||||
return 1;
|
||||
}
|
||||
int Return(SquirrelObject &o)
|
||||
{
|
||||
sq_pushobject(v,o.GetObjectHandle());
|
||||
return 1;
|
||||
}
|
||||
int Return() { return 0; }
|
||||
int ThrowError(const SQChar *error) {
|
||||
return sq_throwerror(v,error);
|
||||
}
|
||||
HSQUIRRELVM GetVMPtr() { return v; }
|
||||
private:
|
||||
int _top;
|
||||
HSQUIRRELVM v;
|
||||
};
|
||||
|
||||
#endif //_SQUIRREL_OBJECT_H_
|
File diff suppressed because it is too large
Load Diff
@ -1,179 +1,179 @@
|
||||
#ifndef _SQUIRREL_VM_H_
|
||||
#define _SQUIRREL_VM_H_
|
||||
|
||||
#include "SquirrelObject.h"
|
||||
|
||||
struct SquirrelError {
|
||||
SquirrelError();
|
||||
SquirrelError(const SQChar* s):desc(s){}
|
||||
const SQChar *desc;
|
||||
};
|
||||
|
||||
// This class can hold a reference to a SquirrelVM. It keeps a Squirrel ref
|
||||
// to the VM to protect it from being deleted while held.
|
||||
struct SquirrelVMSys {
|
||||
SquirrelVMSys() { }
|
||||
~SquirrelVMSys();
|
||||
|
||||
void Set( HSQUIRRELVM v );
|
||||
void Set( const SquirrelObject& ov );
|
||||
void Reset( ){ _vm.Reset(); }
|
||||
|
||||
SquirrelVMSys& operator = (HSQUIRRELVM v){ Set(v); return *this; }
|
||||
operator HSQUIRRELVM () const;
|
||||
|
||||
protected:
|
||||
void PushRefVM(HSQUIRRELVM v);
|
||||
void PopRefVM();
|
||||
SquirrelObject _vm;
|
||||
friend class SquirrelVM;
|
||||
};
|
||||
|
||||
// Notes on creating / destroying SquirrelVM:s:
|
||||
//
|
||||
// VM:s created through sq_open are special since they create a new
|
||||
// SQSharedState. That shared state is later shared by any new thread
|
||||
// or friend VM. sq_close can be used for closing VM:s created through
|
||||
// sq_open (but not for friend VMs).
|
||||
//
|
||||
// Using squirrel references in SquirrelVMSys and SquirrelVM, one must
|
||||
// make sure that these are all reset if one calls sq_close manually.
|
||||
//
|
||||
// When there are no more references to a VM, it is destroyed automatically,
|
||||
// but the shared state is not! For VM:s created by SquirrelVM, it keeps
|
||||
// a list of shared states it has created and will destroy them all on
|
||||
// app shutdown.
|
||||
|
||||
class SquirrelVM {
|
||||
friend class SquirrelObject;
|
||||
friend struct SquirrelError;
|
||||
friend struct SquirrelVMSys;
|
||||
|
||||
public:
|
||||
// If a VM is passed as arg here, Init will not alter it. Otherwise
|
||||
// a new VM is created and initialized. A squirrel reference is kept
|
||||
// while it is the current VM.
|
||||
static bool Init( HSQUIRRELVM v=NULL );
|
||||
|
||||
// Initialize with an externally created VM, without adding a ref
|
||||
// on it. NOTE: This may not be compatible with Set/GetVMSys as
|
||||
// we're just working with raw pointers here.
|
||||
static bool InitNoRef( HSQUIRRELVM v );
|
||||
static BOOL IsInitialized(){return _VM == NULL?FALSE:TRUE;}
|
||||
|
||||
static void Release(); // Release ref on VM and reset VM pointer
|
||||
static void Shutdown(){ Release(); }
|
||||
static void AppFinalShutdown(); // Call when finally shutting down app
|
||||
|
||||
static BOOL Update(); //debugger and maybe GC later
|
||||
|
||||
static SquirrelObject CompileScript(const SQChar *s);
|
||||
static SquirrelObject CompileBuffer(const SQChar *s,const SQChar * debugInfo=_SC("console_buffer"));
|
||||
static SquirrelObject RunScript(const SquirrelObject &o,SquirrelObject *_this = NULL);
|
||||
|
||||
static void PrintFunc(HSQUIRRELVM v,const SQChar* s,...);
|
||||
|
||||
static BOOL BeginCall(const SquirrelObject &func);
|
||||
static BOOL BeginCall(const SquirrelObject &func,SquirrelObject &_this);
|
||||
|
||||
static void PushParam(const SquirrelObject &o);
|
||||
static void PushParam(const SQChar *s);
|
||||
static void PushParam(SQInteger n);
|
||||
static void PushParam(SQFloat f);
|
||||
static void PushParam(SQUserPointer up);
|
||||
static void PushParamNull();
|
||||
|
||||
static SquirrelObject EndCall();
|
||||
static SquirrelObject CreateString(const SQChar *s);
|
||||
static SquirrelObject CreateTable();
|
||||
static SquirrelObject CreateArray(int size);
|
||||
static SquirrelObject CreateInstance(SquirrelObject &oclass); // oclass is an existing class. Create an 'instance' (OT_INSTANCE) of oclass.
|
||||
static SquirrelObject CreateFunction(SQFUNCTION func);
|
||||
static SquirrelObject CreateUserData(int size);
|
||||
|
||||
static const SquirrelObject &GetRootTable();
|
||||
static HSQUIRRELVM GetVMPtr() { return _VM; }
|
||||
|
||||
// The sandbox VM ptr is one which cannot access functions bound with
|
||||
// SqPlus. It is suitable for running non-trusted scripts that can only
|
||||
// access basic functionality.
|
||||
static void SetSandboxVMPtr(HSQUIRRELVM v) {
|
||||
_sandboxVM = v;
|
||||
} // SetSandboxVMPtr
|
||||
|
||||
static HSQUIRRELVM GetSandboxVMPtr() {
|
||||
return _sandboxVM;
|
||||
} // GetSandboxVMPtr
|
||||
|
||||
static void GetVMSys(SquirrelVMSys & vmSys) {
|
||||
vmSys.Set( _vm );
|
||||
} // GetVMSys
|
||||
|
||||
static void SetVMSys(const SquirrelVMSys & vmSys) {
|
||||
Release();
|
||||
HSQUIRRELVM v = (HSQUIRRELVM)vmSys;
|
||||
if( v )
|
||||
Init( v );
|
||||
} // SetVMSys
|
||||
|
||||
static void PushValue(INT val) {
|
||||
sq_pushinteger(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(FLOAT val) {
|
||||
sq_pushfloat(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(bool val) { // Compiler treats SQBool as INT.
|
||||
sq_pushbool(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(SQChar * val) {
|
||||
sq_pushstring(_VM,val,-1);
|
||||
} // PushValue
|
||||
static void PushValue(SQUserPointer val) {
|
||||
sq_pushuserpointer(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(const SQChar * val) {
|
||||
sq_pushstring(_VM,val,-1);
|
||||
} // PushValue
|
||||
static void PushObject(SquirrelObject & so) {
|
||||
sq_pushobject(_VM,so._o);
|
||||
} // PushObject
|
||||
static void Pop(SQInteger nelemstopop) {
|
||||
sq_pop(_VM,nelemstopop);
|
||||
} // Pop
|
||||
|
||||
static void PushRootTable(void);
|
||||
|
||||
// Create/bind a function on the table currently on the stack.
|
||||
static SquirrelObject CreateFunction(SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
// Create/bind a function on the table so. typeMask: standard Squirrel types plus: no typemask means no args, "*" means any type of args.
|
||||
static SquirrelObject CreateFunction(SquirrelObject & so,SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
// Create/bind a function to the root table. typeMask: standard Squirrel types plus: no typemask means no args, "*" means any type of args.
|
||||
static SquirrelObject CreateFunctionGlobal(SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
|
||||
// This is a helper to correct a difference in referncing new VM:s in
|
||||
// ref counted versus garbage collected modes. NOTE: Only use after creating
|
||||
// a VM with: 1 - sq_open() 2 - Creating a ref to the VM (SquirrelObject)
|
||||
static void DropVMRefIfRefCounted( HSQUIRRELVM v );
|
||||
|
||||
|
||||
private:
|
||||
static SquirrelObject _vm; // This is a Squirrel reference to the VM
|
||||
static HSQUIRRELVM _VM; // The raw C++ pointer
|
||||
static bool _no_vm_ref; // Set if we only keep the raw C++ pointer and no ref
|
||||
static int _CallState;
|
||||
static SquirrelObject * _root; // Cached root table if non NULL
|
||||
static HSQUIRRELVM _sandboxVM; // The sandbox VM (that cannot use bound functions)
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline BOOL SquirrelObject::ArrayAppend(T item) {
|
||||
sq_pushobject(SquirrelVM::_VM,GetObjectHandle());
|
||||
SquirrelVM::PushValue(item);
|
||||
BOOL res = sq_arrayappend(SquirrelVM::_VM,-2) == SQ_OK;
|
||||
sq_pop(SquirrelVM::_VM,1);
|
||||
return res;
|
||||
} // ArrayAppend
|
||||
|
||||
#endif //_SQUIRREL_VM_H_
|
||||
|
||||
#ifndef _SQUIRREL_VM_H_
|
||||
#define _SQUIRREL_VM_H_
|
||||
|
||||
#include "SquirrelObject.h"
|
||||
|
||||
struct SquirrelError {
|
||||
SquirrelError();
|
||||
SquirrelError(const SQChar* s):desc(s){}
|
||||
const SQChar *desc;
|
||||
};
|
||||
|
||||
// This class can hold a reference to a SquirrelVM. It keeps a Squirrel ref
|
||||
// to the VM to protect it from being deleted while held.
|
||||
struct SquirrelVMSys {
|
||||
SquirrelVMSys() { }
|
||||
~SquirrelVMSys();
|
||||
|
||||
void Set( HSQUIRRELVM v );
|
||||
void Set( const SquirrelObject& ov );
|
||||
void Reset( ){ _vm.Reset(); }
|
||||
|
||||
SquirrelVMSys& operator = (HSQUIRRELVM v){ Set(v); return *this; }
|
||||
operator HSQUIRRELVM () const;
|
||||
|
||||
protected:
|
||||
void PushRefVM(HSQUIRRELVM v);
|
||||
void PopRefVM();
|
||||
SquirrelObject _vm;
|
||||
friend class SquirrelVM;
|
||||
};
|
||||
|
||||
// Notes on creating / destroying SquirrelVM:s:
|
||||
//
|
||||
// VM:s created through sq_open are special since they create a new
|
||||
// SQSharedState. That shared state is later shared by any new thread
|
||||
// or friend VM. sq_close can be used for closing VM:s created through
|
||||
// sq_open (but not for friend VMs).
|
||||
//
|
||||
// Using squirrel references in SquirrelVMSys and SquirrelVM, one must
|
||||
// make sure that these are all reset if one calls sq_close manually.
|
||||
//
|
||||
// When there are no more references to a VM, it is destroyed automatically,
|
||||
// but the shared state is not! For VM:s created by SquirrelVM, it keeps
|
||||
// a list of shared states it has created and will destroy them all on
|
||||
// app shutdown.
|
||||
|
||||
class SquirrelVM {
|
||||
friend class SquirrelObject;
|
||||
friend struct SquirrelError;
|
||||
friend struct SquirrelVMSys;
|
||||
|
||||
public:
|
||||
// If a VM is passed as arg here, Init will not alter it. Otherwise
|
||||
// a new VM is created and initialized. A squirrel reference is kept
|
||||
// while it is the current VM.
|
||||
static bool Init( HSQUIRRELVM v=NULL );
|
||||
|
||||
// Initialize with an externally created VM, without adding a ref
|
||||
// on it. NOTE: This may not be compatible with Set/GetVMSys as
|
||||
// we're just working with raw pointers here.
|
||||
static bool InitNoRef( HSQUIRRELVM v );
|
||||
static BOOL IsInitialized(){return _VM == NULL?FALSE:TRUE;}
|
||||
|
||||
static void Release(); // Release ref on VM and reset VM pointer
|
||||
static void Shutdown(){ Release(); }
|
||||
static void AppFinalShutdown(); // Call when finally shutting down app
|
||||
|
||||
static BOOL Update(); //debugger and maybe GC later
|
||||
|
||||
static SquirrelObject CompileScript(const SQChar *s);
|
||||
static SquirrelObject CompileBuffer(const SQChar *s,const SQChar * debugInfo=_SC("console_buffer"));
|
||||
static SquirrelObject RunScript(const SquirrelObject &o,SquirrelObject *_this = NULL);
|
||||
|
||||
static void PrintFunc(HSQUIRRELVM v,const SQChar* s,...);
|
||||
|
||||
static BOOL BeginCall(const SquirrelObject &func);
|
||||
static BOOL BeginCall(const SquirrelObject &func,SquirrelObject &_this);
|
||||
|
||||
static void PushParam(const SquirrelObject &o);
|
||||
static void PushParam(const SQChar *s);
|
||||
static void PushParam(SQInteger n);
|
||||
static void PushParam(SQFloat f);
|
||||
static void PushParam(SQUserPointer up);
|
||||
static void PushParamNull();
|
||||
|
||||
static SquirrelObject EndCall();
|
||||
static SquirrelObject CreateString(const SQChar *s);
|
||||
static SquirrelObject CreateTable();
|
||||
static SquirrelObject CreateArray(int size);
|
||||
static SquirrelObject CreateInstance(SquirrelObject &oclass); // oclass is an existing class. Create an 'instance' (OT_INSTANCE) of oclass.
|
||||
static SquirrelObject CreateFunction(SQFUNCTION func);
|
||||
static SquirrelObject CreateUserData(int size);
|
||||
|
||||
static const SquirrelObject &GetRootTable();
|
||||
static HSQUIRRELVM GetVMPtr() { return _VM; }
|
||||
|
||||
// The sandbox VM ptr is one which cannot access functions bound with
|
||||
// SqPlus. It is suitable for running non-trusted scripts that can only
|
||||
// access basic functionality.
|
||||
static void SetSandboxVMPtr(HSQUIRRELVM v) {
|
||||
_sandboxVM = v;
|
||||
} // SetSandboxVMPtr
|
||||
|
||||
static HSQUIRRELVM GetSandboxVMPtr() {
|
||||
return _sandboxVM;
|
||||
} // GetSandboxVMPtr
|
||||
|
||||
static void GetVMSys(SquirrelVMSys & vmSys) {
|
||||
vmSys.Set( _vm );
|
||||
} // GetVMSys
|
||||
|
||||
static void SetVMSys(const SquirrelVMSys & vmSys) {
|
||||
Release();
|
||||
HSQUIRRELVM v = (HSQUIRRELVM)vmSys;
|
||||
if( v )
|
||||
Init( v );
|
||||
} // SetVMSys
|
||||
|
||||
static void PushValue(INT val) {
|
||||
sq_pushinteger(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(FLOAT val) {
|
||||
sq_pushfloat(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(bool val) { // Compiler treats SQBool as INT.
|
||||
sq_pushbool(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(SQChar * val) {
|
||||
sq_pushstring(_VM,val,-1);
|
||||
} // PushValue
|
||||
static void PushValue(SQUserPointer val) {
|
||||
sq_pushuserpointer(_VM,val);
|
||||
} // PushValue
|
||||
static void PushValue(const SQChar * val) {
|
||||
sq_pushstring(_VM,val,-1);
|
||||
} // PushValue
|
||||
static void PushObject(SquirrelObject & so) {
|
||||
sq_pushobject(_VM,so._o);
|
||||
} // PushObject
|
||||
static void Pop(SQInteger nelemstopop) {
|
||||
sq_pop(_VM,nelemstopop);
|
||||
} // Pop
|
||||
|
||||
static void PushRootTable(void);
|
||||
|
||||
// Create/bind a function on the table currently on the stack.
|
||||
static SquirrelObject CreateFunction(SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
// Create/bind a function on the table so. typeMask: standard Squirrel types plus: no typemask means no args, "*" means any type of args.
|
||||
static SquirrelObject CreateFunction(SquirrelObject & so,SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
// Create/bind a function to the root table. typeMask: standard Squirrel types plus: no typemask means no args, "*" means any type of args.
|
||||
static SquirrelObject CreateFunctionGlobal(SQFUNCTION func,const SQChar * scriptFuncName,const SQChar * typeMask=0);
|
||||
|
||||
// This is a helper to correct a difference in referncing new VM:s in
|
||||
// ref counted versus garbage collected modes. NOTE: Only use after creating
|
||||
// a VM with: 1 - sq_open() 2 - Creating a ref to the VM (SquirrelObject)
|
||||
static void DropVMRefIfRefCounted( HSQUIRRELVM v );
|
||||
|
||||
|
||||
private:
|
||||
static SquirrelObject _vm; // This is a Squirrel reference to the VM
|
||||
static HSQUIRRELVM _VM; // The raw C++ pointer
|
||||
static bool _no_vm_ref; // Set if we only keep the raw C++ pointer and no ref
|
||||
static int _CallState;
|
||||
static SquirrelObject * _root; // Cached root table if non NULL
|
||||
static HSQUIRRELVM _sandboxVM; // The sandbox VM (that cannot use bound functions)
|
||||
};
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline BOOL SquirrelObject::ArrayAppend(T item) {
|
||||
sq_pushobject(SquirrelVM::_VM,GetObjectHandle());
|
||||
SquirrelVM::PushValue(item);
|
||||
BOOL res = sq_arrayappend(SquirrelVM::_VM,-2) == SQ_OK;
|
||||
sq_pop(SquirrelVM::_VM,1);
|
||||
return res;
|
||||
} // ArrayAppend
|
||||
|
||||
#endif //_SQUIRREL_VM_H_
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,7 @@
|
||||
#ifndef _SQ_PLUS_WIN32_H_
|
||||
#define _SQ_PLUS_WIN32_H_
|
||||
|
||||
#include "sqplus.h"
|
||||
#include "SquirrelBindingsUtilsWin32.h"
|
||||
|
||||
#ifndef _SQ_PLUS_WIN32_H_
|
||||
#define _SQ_PLUS_WIN32_H_
|
||||
|
||||
#include "sqplus.h"
|
||||
#include "SquirrelBindingsUtilsWin32.h"
|
||||
|
||||
#endif //_SQ_PLUS_WIN32_H_
|
199
squirrel_3_0_1_stable/sqrat/sqmodule.h
Normal file
199
squirrel_3_0_1_stable/sqrat/sqmodule.h
Normal file
@ -0,0 +1,199 @@
|
||||
//
|
||||
// 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_*/
|
41
squirrel_3_0_1_stable/sqrat/sqrat.h
Normal file
41
squirrel_3_0_1_stable/sqrat/sqrat.h
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// 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
|
134
squirrel_3_0_1_stable/sqrat/sqrat/sqratAllocator.h
Normal file
134
squirrel_3_0_1_stable/sqrat/sqrat/sqratAllocator.h
Normal file
@ -0,0 +1,134 @@
|
||||
//
|
||||
// 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
|
210
squirrel_3_0_1_stable/sqrat/sqrat/sqratArray.h
Normal file
210
squirrel_3_0_1_stable/sqrat/sqrat/sqratArray.h
Normal file
@ -0,0 +1,210 @@
|
||||
|
||||
//
|
||||
// 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
|
415
squirrel_3_0_1_stable/sqrat/sqrat/sqratClass.h
Normal file
415
squirrel_3_0_1_stable/sqrat/sqrat/sqratClass.h
Normal file
@ -0,0 +1,415 @@
|
||||
|
||||
//
|
||||
// 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
|
126
squirrel_3_0_1_stable/sqrat/sqrat/sqratClassType.h
Normal file
126
squirrel_3_0_1_stable/sqrat/sqrat/sqratClassType.h
Normal file
@ -0,0 +1,126 @@
|
||||
|
||||
//
|
||||
// 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
|
120
squirrel_3_0_1_stable/sqrat/sqrat/sqratConst.h
Normal file
120
squirrel_3_0_1_stable/sqrat/sqrat/sqratConst.h
Normal file
@ -0,0 +1,120 @@
|
||||
//
|
||||
// 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
|
751
squirrel_3_0_1_stable/sqrat/sqrat/sqratFunction.h
Normal file
751
squirrel_3_0_1_stable/sqrat/sqrat/sqratFunction.h
Normal file
@ -0,0 +1,751 @@
|
||||
//
|
||||
// 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
|
835
squirrel_3_0_1_stable/sqrat/sqrat/sqratGlobalMethods.h
Normal file
835
squirrel_3_0_1_stable/sqrat/sqrat/sqratGlobalMethods.h
Normal file
@ -0,0 +1,835 @@
|
||||
//
|
||||
// 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
|
1706
squirrel_3_0_1_stable/sqrat/sqrat/sqratMemberMethods.h
Normal file
1706
squirrel_3_0_1_stable/sqrat/sqrat/sqratMemberMethods.h
Normal file
File diff suppressed because it is too large
Load Diff
310
squirrel_3_0_1_stable/sqrat/sqrat/sqratObject.h
Normal file
310
squirrel_3_0_1_stable/sqrat/sqrat/sqratObject.h
Normal file
@ -0,0 +1,310 @@
|
||||
//
|
||||
// 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
|
485
squirrel_3_0_1_stable/sqrat/sqrat/sqratOverloadMethods.h
Normal file
485
squirrel_3_0_1_stable/sqrat/sqrat/sqratOverloadMethods.h
Normal file
@ -0,0 +1,485 @@
|
||||
//
|
||||
// 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
|
141
squirrel_3_0_1_stable/sqrat/sqrat/sqratScript.h
Normal file
141
squirrel_3_0_1_stable/sqrat/sqrat/sqratScript.h
Normal file
@ -0,0 +1,141 @@
|
||||
//
|
||||
// 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
|
162
squirrel_3_0_1_stable/sqrat/sqrat/sqratTable.h
Normal file
162
squirrel_3_0_1_stable/sqrat/sqrat/sqratTable.h
Normal file
@ -0,0 +1,162 @@
|
||||
//
|
||||
// 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
|
341
squirrel_3_0_1_stable/sqrat/sqrat/sqratTypes.h
Normal file
341
squirrel_3_0_1_stable/sqrat/sqrat/sqratTypes.h
Normal file
@ -0,0 +1,341 @@
|
||||
//
|
||||
// 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
|
94
squirrel_3_0_1_stable/sqrat/sqrat/sqratUtil.h
Normal file
94
squirrel_3_0_1_stable/sqrat/sqrat/sqratUtil.h
Normal file
@ -0,0 +1,94 @@
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
#if !defined(_SCRAT_UTIL_H_)
|
||||
#define _SCRAT_UTIL_H_
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "sqratTypes.h"
|
||||
|
||||
namespace Sqrat {
|
||||
|
||||
class DefaultVM {
|
||||
private:
|
||||
static HSQUIRRELVM& staticVm() {
|
||||
static HSQUIRRELVM vm;
|
||||
return vm;
|
||||
}
|
||||
public:
|
||||
static HSQUIRRELVM Get() {
|
||||
return staticVm();
|
||||
}
|
||||
static void Set(HSQUIRRELVM vm) {
|
||||
staticVm() = vm;
|
||||
}
|
||||
};
|
||||
|
||||
class ErrorHandling {
|
||||
private:
|
||||
static bool& errorHandling() {
|
||||
static bool eh = true;
|
||||
return eh;
|
||||
}
|
||||
public:
|
||||
static bool IsEnabled() {
|
||||
return errorHandling();
|
||||
}
|
||||
static void Enable(bool enable) {
|
||||
errorHandling() = enable;
|
||||
}
|
||||
};
|
||||
|
||||
class Exception {
|
||||
public:
|
||||
Exception(const string& msg) : message(msg) {}
|
||||
Exception(const Exception& ex) : message(ex.message) {}
|
||||
|
||||
const string Message() const {
|
||||
return message;
|
||||
}
|
||||
|
||||
private:
|
||||
string message;
|
||||
};
|
||||
|
||||
inline string LastErrorString( HSQUIRRELVM vm ) {
|
||||
const SQChar* sqErr;
|
||||
sq_getlasterror(vm);
|
||||
if(sq_gettype(vm, -1) == OT_NULL) {
|
||||
return string();
|
||||
}
|
||||
sq_tostring(vm, -1);
|
||||
sq_getstring(vm, -1, &sqErr);
|
||||
return string(sqErr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
255
squirrel_3_0_1_stable/sqrat/sqrat/sqratVM.h
Normal file
255
squirrel_3_0_1_stable/sqrat/sqrat/sqratVM.h
Normal file
@ -0,0 +1,255 @@
|
||||
// wrapper for the Squirrel VM under Sqrat
|
||||
//
|
||||
// Copyright (c) 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_VM_H_)
|
||||
#define _SCRAT_VM_H_
|
||||
|
||||
#include <squirrel.h>
|
||||
#include <sqrat.h>
|
||||
#include <map>
|
||||
|
||||
#include <iostream>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sqstdio.h>
|
||||
#include <sqstdblob.h>
|
||||
#include <sqstdmath.h>
|
||||
#include <sqstdsystem.h>
|
||||
#include <sqstdstring.h>
|
||||
|
||||
namespace Sqrat {
|
||||
|
||||
class SqratVM
|
||||
{
|
||||
private:
|
||||
static std::map<HSQUIRRELVM, SqratVM*> ms_sqratVMs;
|
||||
static void s_addVM(HSQUIRRELVM vm, SqratVM* sqratvm);
|
||||
static void s_deleteVM(HSQUIRRELVM vm);
|
||||
static SqratVM* s_getVM(HSQUIRRELVM vm);
|
||||
|
||||
HSQUIRRELVM m_vm;
|
||||
Sqrat::RootTable* m_rootTable;
|
||||
Sqrat::Script* m_script;
|
||||
Sqrat::string m_lastErrorMsg;
|
||||
|
||||
private:
|
||||
static void printFunc(HSQUIRRELVM v, const SQChar *s, ...);
|
||||
static SQInteger runtimeErrorHandler(HSQUIRRELVM v);
|
||||
static void compilerErrorHandler(HSQUIRRELVM v,
|
||||
const SQChar* desc,
|
||||
const SQChar* source,
|
||||
SQInteger line,
|
||||
SQInteger column);
|
||||
public:
|
||||
enum ERROR_STATE
|
||||
{
|
||||
NO_ERROR, COMPILE_ERROR, RUNTIME_ERROR
|
||||
};
|
||||
|
||||
SqratVM(int initialStackSize = 1024);
|
||||
~SqratVM();
|
||||
|
||||
HSQUIRRELVM getVM() { return m_vm; }
|
||||
Sqrat::RootTable& getRootTable() { return *m_rootTable; }
|
||||
Sqrat::Script& getScript() { return *m_script; }
|
||||
|
||||
Sqrat::string getLastErrorMsg() { return m_lastErrorMsg; }
|
||||
void setLastErrorMsg(const Sqrat::string& str) { m_lastErrorMsg = str; }
|
||||
|
||||
void setPrintFunc(SQPRINTFUNCTION printFunc, SQPRINTFUNCTION errFunc);
|
||||
void setErrorHandler(SQFUNCTION runErr, SQCOMPILERERROR comErr);
|
||||
|
||||
ERROR_STATE doString(const Sqrat::string& str);
|
||||
ERROR_STATE doFile(const Sqrat::string& file);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef SQUNICODE
|
||||
#define scvprintf vwprintf
|
||||
#else
|
||||
#define scvprintf vprintf
|
||||
#endif
|
||||
|
||||
|
||||
std::map<HSQUIRRELVM, SqratVM*> SqratVM::ms_sqratVMs;
|
||||
|
||||
void SqratVM::s_addVM(HSQUIRRELVM vm, SqratVM* sqratvm)
|
||||
{
|
||||
//TODO: use mutex to lock ms_sqratVMs
|
||||
ms_sqratVMs.insert(std::make_pair(vm, sqratvm));
|
||||
}
|
||||
void SqratVM::s_deleteVM(HSQUIRRELVM vm)
|
||||
{
|
||||
//TODO: use mutex to lock ms_sqratVMs
|
||||
ms_sqratVMs.erase(vm);
|
||||
}
|
||||
SqratVM* SqratVM::s_getVM(HSQUIRRELVM vm)
|
||||
{
|
||||
//TODO: use mutex to lock ms_sqratVMs
|
||||
return ms_sqratVMs[vm];
|
||||
}
|
||||
|
||||
void SqratVM::printFunc(HSQUIRRELVM v, const SQChar *s, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvprintf(s, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
SQInteger SqratVM::runtimeErrorHandler(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *sErr = 0;
|
||||
if(sq_gettop(v) >= 1)
|
||||
{
|
||||
Sqrat::string& errStr = s_getVM(v)->m_lastErrorMsg;
|
||||
|
||||
if(SQ_SUCCEEDED(sq_getstring(v, 2, &sErr)))
|
||||
{
|
||||
//scprintf(_SC("RuntimeError: %s\n"), sErr);
|
||||
//errStr = _SC("RuntimeError: ") + sErr;
|
||||
errStr = sErr;
|
||||
}
|
||||
else
|
||||
{
|
||||
//scprintf(_SC("An Unknown RuntimeError Occured.\n"));
|
||||
errStr = _SC("An Unknown RuntimeError Occured.");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SqratVM::compilerErrorHandler(HSQUIRRELVM v,
|
||||
const SQChar* desc,
|
||||
const SQChar* source,
|
||||
SQInteger line,
|
||||
SQInteger column)
|
||||
{
|
||||
//scprintf(_SC("%s(%d:%d): %s\n"), source, line, column, desc);
|
||||
|
||||
SQChar buf[512];
|
||||
scsprintf(buf, _SC("%s(%d:%d): %s"), source, line, column, desc);
|
||||
s_getVM(v)->m_lastErrorMsg = buf;
|
||||
}
|
||||
|
||||
SqratVM::SqratVM(int initialStackSize /* = 1024 */)
|
||||
: m_vm(sq_open(initialStackSize))
|
||||
, m_rootTable(new Sqrat::RootTable(m_vm))
|
||||
, m_script(new Sqrat::Script(m_vm))
|
||||
, m_lastErrorMsg()
|
||||
{
|
||||
s_addVM(m_vm, this);
|
||||
|
||||
//register std libs
|
||||
sq_pushroottable(m_vm);
|
||||
sqstd_register_iolib(m_vm);
|
||||
sqstd_register_bloblib(m_vm);
|
||||
sqstd_register_mathlib(m_vm);
|
||||
sqstd_register_systemlib(m_vm);
|
||||
sqstd_register_stringlib(m_vm);
|
||||
sq_pop(m_vm, 1);
|
||||
|
||||
setPrintFunc(printFunc, printFunc);
|
||||
setErrorHandler(runtimeErrorHandler, compilerErrorHandler);
|
||||
}
|
||||
|
||||
SqratVM::~SqratVM()
|
||||
{
|
||||
s_deleteVM(m_vm);
|
||||
|
||||
delete m_script;
|
||||
delete m_rootTable;
|
||||
sq_close(m_vm);
|
||||
}
|
||||
|
||||
void SqratVM::setPrintFunc(SQPRINTFUNCTION printFunc, SQPRINTFUNCTION errFunc)
|
||||
{
|
||||
sq_setprintfunc(m_vm, printFunc, errFunc);
|
||||
}
|
||||
|
||||
void SqratVM::setErrorHandler(SQFUNCTION runErr, SQCOMPILERERROR comErr)
|
||||
{
|
||||
sq_newclosure(m_vm, runErr, 0);
|
||||
sq_seterrorhandler(m_vm);
|
||||
|
||||
sq_setcompilererrorhandler(m_vm, comErr);
|
||||
}
|
||||
|
||||
SqratVM::ERROR_STATE SqratVM::doString(const Sqrat::string& str)
|
||||
{
|
||||
Sqrat::string msg;
|
||||
m_lastErrorMsg.clear();
|
||||
|
||||
if(!m_script->CompileString(str, msg))
|
||||
{
|
||||
if(m_lastErrorMsg.empty())
|
||||
{
|
||||
m_lastErrorMsg = msg;
|
||||
}
|
||||
return COMPILE_ERROR;
|
||||
}
|
||||
|
||||
if(!m_script->Run(msg))
|
||||
{
|
||||
if(m_lastErrorMsg.empty())
|
||||
{
|
||||
m_lastErrorMsg = msg;
|
||||
}
|
||||
return RUNTIME_ERROR;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
SqratVM::ERROR_STATE SqratVM::doFile(const Sqrat::string& file)
|
||||
{
|
||||
Sqrat::string msg;
|
||||
m_lastErrorMsg.clear();
|
||||
|
||||
if(!m_script->CompileFile(file, msg))
|
||||
{
|
||||
if(m_lastErrorMsg.empty())
|
||||
{
|
||||
m_lastErrorMsg = msg;
|
||||
}
|
||||
return COMPILE_ERROR;
|
||||
}
|
||||
|
||||
if(!m_script->Run(msg))
|
||||
{
|
||||
if(m_lastErrorMsg.empty())
|
||||
{
|
||||
m_lastErrorMsg = msg;
|
||||
}
|
||||
return RUNTIME_ERROR;
|
||||
}
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
45
squirrel_3_0_1_stable/sqrat/sqratimport.h
Normal file
45
squirrel_3_0_1_stable/sqrat/sqratimport.h
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// SqImport: Supports importing of 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_IMPORT_H_)
|
||||
#define _SQ_IMPORT_H_
|
||||
|
||||
#include <squirrel.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SQUIRREL_API SQRESULT sqrat_import(HSQUIRRELVM v);
|
||||
|
||||
SQUIRREL_API SQRESULT sqrat_register_importlib(HSQUIRRELVM v);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /*extern "C"*/
|
||||
#endif
|
||||
|
||||
#endif /*_SQ_IMPORT_H_*/
|
Loading…
Reference in New Issue
Block a user