mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
************************************************************
* Merged Source Code from Development Trunk: Revision 4063 * ************************************************************ - Source Code is merged from: https://81.169.133.124/source/ja2/branches/Wanne/JA2%201.13%20MP - This will be the Source for the Beta 2011 Test git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@4064 3b4a5df2-a311-0410-b5c6-a8a6f20db521
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#ifndef _LUA_INTERPRETER_H_
|
||||
#define _LUA_INTERPRETER_H_
|
||||
|
||||
extern "C" {
|
||||
#include "lua.h"
|
||||
#include "lauxlib.h"
|
||||
@@ -29,3 +32,5 @@ void NewLuaObject( lua_State *L, STR8 ClsName, void *Ptr );
|
||||
void LuaStrategicSetup(lua_State *L);
|
||||
void LuaTacticalSetup(lua_State *L);
|
||||
void LuaEnvironmentSetup(lua_State *L);
|
||||
|
||||
#endif // _LUA_INTERPRETER_H_
|
||||
|
||||
@@ -0,0 +1,431 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="lua"
|
||||
ProjectGUID="{A83DA7DA-2C31-45D8-9A69-B4993A885E76}"
|
||||
RootNamespace="lua"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="..\lib\VS2005\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2005\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Debug.vsprops"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
DisableSpecificWarnings="4100"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="..\lib\VS2005\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2005\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2.vsprops"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditor|Win32"
|
||||
OutputDirectory="..\lib\VS2005\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2005\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Editor.vsprops"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="MapEditorD|Win32"
|
||||
OutputDirectory="..\lib\VS2005\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2005\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Editor.vsprops"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_LIB;"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="1"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
DisableSpecificWarnings="4100"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release_WithDebugInfo|Win32"
|
||||
OutputDirectory="..\lib\VS2005\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2005\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2.vsprops"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
AdditionalOptions="/D "_CRT_SECURE_NO_DEPRECATE""
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;"
|
||||
RuntimeLibrary="0"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLibrarianTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath="lauxlib.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="Lua Interpreter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\Lua Interpreter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="lua.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="lua.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_class_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\luaconf.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lualib.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lwstring.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath="lua.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_class_interface.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_env.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_function.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_state.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_strategic.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_table.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_tactical.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lwstring.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
+37
-5
@@ -21,7 +21,7 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Debug.vsprops"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Debug.vsprops"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
@@ -83,7 +83,7 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
InheritedPropertySheets="..\ja2.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
@@ -147,7 +147,7 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Editor.vsprops"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Editor.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
@@ -211,7 +211,7 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops;..\ja2_VS2008Editor.vsprops"
|
||||
InheritedPropertySheets="..\ja2.vsprops;..\ja2_Editor.vsprops"
|
||||
CharacterSet="0"
|
||||
>
|
||||
<Tool
|
||||
@@ -273,7 +273,7 @@
|
||||
OutputDirectory="..\lib\VS2008\$(ConfigurationName)"
|
||||
IntermediateDirectory="..\build\VS2008\$(ProjectName)_$(ConfigurationName)"
|
||||
ConfigurationType="4"
|
||||
InheritedPropertySheets="..\ja2_VS2008.vsprops"
|
||||
InheritedPropertySheets="..\ja2.vsprops"
|
||||
CharacterSet="0"
|
||||
WholeProgramOptimization="0"
|
||||
>
|
||||
@@ -355,6 +355,22 @@
|
||||
RelativePath="lua.hpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_class_interface.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_function.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_state.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_table.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="luaconf.h"
|
||||
>
|
||||
@@ -375,14 +391,30 @@
|
||||
RelativePath="lua.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_class_interface.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="lua_env.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_function.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_state.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="lua_strategic.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\lua_table.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="lua_tactical.cpp"
|
||||
>
|
||||
|
||||
@@ -0,0 +1,233 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="MapEditorD|Win32">
|
||||
<Configuration>MapEditorD</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="MapEditor|Win32">
|
||||
<Configuration>MapEditor</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Relese_WithDebugInfo|Win32">
|
||||
<Configuration>Relese_WithDebugInfo</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="lauxlib.h" />
|
||||
<ClInclude Include="Lua Interpreter.h" />
|
||||
<ClInclude Include="lua.h" />
|
||||
<ClInclude Include="lua.hpp" />
|
||||
<ClInclude Include="luaconf.h" />
|
||||
<ClInclude Include="lualib.h" />
|
||||
<ClInclude Include="lua_class_interface.h" />
|
||||
<ClInclude Include="lua_function.h" />
|
||||
<ClInclude Include="lua_state.h" />
|
||||
<ClInclude Include="lua_table.h" />
|
||||
<ClInclude Include="lwstring.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="lua.cpp" />
|
||||
<ClCompile Include="lua_class_interface.cpp" />
|
||||
<ClCompile Include="lua_env.cpp" />
|
||||
<ClCompile Include="lua_function.cpp" />
|
||||
<ClCompile Include="lua_state.cpp" />
|
||||
<ClCompile Include="lua_strategic.cpp" />
|
||||
<ClCompile Include="lua_table.cpp" />
|
||||
<ClCompile Include="lua_tactical.cpp" />
|
||||
<ClCompile Include="lwstring.cpp" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{9DA9FE0C-B1F2-4E15-9097-A929E203AC28}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>lua</RootNamespace>
|
||||
<ProjectName>lua</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MapEditorD|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MapEditor|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Relese_WithDebugInfo|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>false</WholeProgramOptimization>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ja2.props" />
|
||||
<Import Project="..\ja2_Debug.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MapEditorD|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ja2.props" />
|
||||
<Import Project="..\ja2_Debug.props" />
|
||||
<Import Project="..\ja2_Editor.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ja2.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='MapEditor|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ja2.props" />
|
||||
<Import Project="..\ja2_Editor.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Relese_WithDebugInfo|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\ja2.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>..\lib\VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>..\build\VS2010\$(ProjectName)_$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MapEditorD|Win32'">
|
||||
<OutDir>..\lib\VS2010\$(Configuration)\</OutDir>
|
||||
<IntDir>..\build\VS2010\$(ProjectName)_$(Configuration)\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IntDir>..\build\VS2010\$(ProjectName)_$(Configuration)\</IntDir>
|
||||
<OutDir>..\lib\VS2010\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='MapEditor|Win32'">
|
||||
<IntDir>..\build\VS2010\$(ProjectName)_$(Configuration)\</IntDir>
|
||||
<OutDir>..\lib\VS2010\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Relese_WithDebugInfo|Win32'">
|
||||
<IntDir>..\build\VS2010\$(ProjectName)_$(Configuration)\</IntDir>
|
||||
<OutDir>..\lib\VS2010\$(Configuration)\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MapEditorD|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='MapEditor|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Relese_WithDebugInfo|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<PrecompiledHeaderFile>
|
||||
</PrecompiledHeaderFile>
|
||||
<PrecompiledHeaderOutputFile>
|
||||
</PrecompiledHeaderOutputFile>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{363547e5-d794-4293-8484-b7cc64b304dd}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{ffb119e4-d4fc-4b6b-93ae-2958a9ec49dc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="lauxlib.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Lua Interpreter.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lua.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lua.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="luaconf.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lualib.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lwstring.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lua_class_interface.h" />
|
||||
<ClInclude Include="lua_function.h" />
|
||||
<ClInclude Include="lua_state.h" />
|
||||
<ClInclude Include="lua_table.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="lua_env.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua_strategic.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua_tactical.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lwstring.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lua_class_interface.cpp" />
|
||||
<ClCompile Include="lua_function.cpp" />
|
||||
<ClCompile Include="lua_state.cpp" />
|
||||
<ClCompile Include="lua_table.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,247 @@
|
||||
#include "lua_class_interface.h"
|
||||
|
||||
#include <Debug.h>
|
||||
|
||||
#define ARRAY_INDEX " idx" // The space is intentional to make this an out-of-band field
|
||||
|
||||
luaL_Reg LuaInterface::s_ClassList[] = {
|
||||
{ "__index", LuaInterface::luaGetObject, },
|
||||
{ "__newindex", LuaInterface::luaSetObject, },
|
||||
{ NULL, },
|
||||
};
|
||||
|
||||
const char* LuaInterface::luaClassName = "ja2_LuaInterface";
|
||||
|
||||
LuaInterface::LuaInterface()
|
||||
: luaObject(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
LuaInterface::~LuaInterface()
|
||||
{
|
||||
}
|
||||
|
||||
LuaInterface::SInterfaceData* LuaInterface::luaGetInterface()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void* LuaInterface::luaIsOfType(LuaState state, int index, const char* sClassName)
|
||||
{
|
||||
lua_State* L = state();
|
||||
void *p = lua_touserdata(L, index);
|
||||
LuaInterface::SInterfaceData* iface = NULL;
|
||||
if( lua_getmetatable(L, index) ) /* does it have a metatable? */
|
||||
{
|
||||
lua_getfield(L, -1, "__ClassInterface");
|
||||
iface = (LuaInterface::SInterfaceData*) lua_touserdata(L, -1);
|
||||
if( !iface )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
lua_pop(L,2);
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
LuaInterface::SInterfaceData::tClassInterface::iterator it = iface->ClassHierarchy.begin();
|
||||
for(; it != iface->ClassHierarchy.end(); ++it)
|
||||
{
|
||||
if( *it == sClassName )
|
||||
{
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LuaInterface::SInterfaceData* LuaInterface::luaGetExportedInterface( SInterfaceData* iface )
|
||||
{
|
||||
//iface.Attribs.push_back(s_attrClassList);
|
||||
//iface.ClassHierarchy.push_back(LuaInterface::luaClassName);
|
||||
return iface;
|
||||
}
|
||||
|
||||
void LuaInterface::luaExportInterface(LuaState state, LuaInterface::SInterfaceData& iface )
|
||||
{
|
||||
luaL_Reg *i;
|
||||
LuaAttrib *idx;
|
||||
lua_State* L = state();
|
||||
|
||||
LuaInterface::SInterfaceData::tClassInterface::iterator it_class = iface.ClassHierarchy.begin();
|
||||
|
||||
luaL_newmetatable( L, (*it_class).c_str() );
|
||||
for (i = s_ClassList; i->name; i++)
|
||||
{
|
||||
lua_pushstring(L, i->name);
|
||||
lua_pushlightuserdata(L, &iface);
|
||||
lua_pushcclosure(L, i->func, 1);
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
lua_pushlightuserdata(L, &iface);
|
||||
lua_setfield(L, -2, "__ClassInterface");
|
||||
|
||||
LuaInterface::SInterfaceData::tAttribs::iterator it_attrib = iface.Attribs.begin();
|
||||
for(;it_attrib != iface.Attribs.end(); ++it_attrib)
|
||||
{
|
||||
for (idx=*it_attrib; idx->name; idx++)
|
||||
{
|
||||
if (idx->staticcall)
|
||||
{
|
||||
lua_pushstring(L, idx->name);
|
||||
lua_pushcfunction(L, idx->staticcall);
|
||||
lua_rawset(L, -3 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LuaAttrib* LuaInterface::luaCommonGetSet(LuaState state)
|
||||
{
|
||||
const char *AttrToFind;
|
||||
typedef std::list<LuaAttrib*> tAttributes;
|
||||
lua_State* L = state();
|
||||
|
||||
LuaInterface::SInterfaceData* iface = (LuaInterface::SInterfaceData*) lua_touserdata(L, lua_upvalueindex( 1));
|
||||
if(!iface)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
tAttributes* Attributes = &iface->Attribs;
|
||||
|
||||
if (lua_isnumber(L, 2) )
|
||||
{
|
||||
AttrToFind = ARRAY_INDEX;
|
||||
}
|
||||
else if (lua_isstring(L, 2) )
|
||||
{
|
||||
AttrToFind = lua_tostring(L, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
luaL_argcheck(L, 0, 2, "Invalid index to the table" );
|
||||
// The last function doesn't return, but gotta keep the compiler happy
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tAttributes::iterator it = Attributes->begin();
|
||||
for(;it != Attributes->end(); ++it)
|
||||
{
|
||||
LuaAttrib* attrib = (*it);
|
||||
for ( ; attrib->name; attrib++ )
|
||||
{
|
||||
if ( strcmp( attrib->name, AttrToFind) == 0 )
|
||||
{
|
||||
return attrib;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::string err = "No such field : " + std::string(AttrToFind);
|
||||
luaL_error(L, err.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//int LuaInterface::luaGetObject(lua_State* L)
|
||||
DEFINE_LUA_CFUNCTION(LuaInterface, luaGetObject)
|
||||
{
|
||||
LuaAttrib *Attributes;
|
||||
|
||||
Attributes = LuaInterface::luaCommonGetSet(L);
|
||||
if (!Attributes)
|
||||
{
|
||||
lua_pushnil( L );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!Attributes->get)
|
||||
{
|
||||
if (!Attributes->call)
|
||||
{
|
||||
lua_pushnil( L );
|
||||
}
|
||||
else
|
||||
{
|
||||
lua_pushcfunction(L, Attributes->call);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
return Attributes->get( L );
|
||||
}
|
||||
|
||||
//int LuaInterface::luaSetObject(lua_State* L)
|
||||
DEFINE_LUA_CFUNCTION(LuaInterface, luaSetObject)
|
||||
{
|
||||
LuaAttrib *Attributes;
|
||||
|
||||
Attributes = LuaInterface::luaCommonGetSet(L);
|
||||
|
||||
if (!Attributes)
|
||||
{
|
||||
lua_rawset( L, 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!Attributes->set)
|
||||
{
|
||||
luaL_error( L, "The attribute is not writable" );
|
||||
}
|
||||
|
||||
return Attributes->set(L);
|
||||
}
|
||||
|
||||
|
||||
void LuaInterface::luaCreateObject( LuaState state, void *Ptr )
|
||||
{
|
||||
lua_State* L = state();
|
||||
// Create the object and initialize its pointer
|
||||
void **ud;
|
||||
ud = (void**)lua_newuserdata( L, sizeof( void*) );
|
||||
*ud = Ptr;
|
||||
// save user data
|
||||
state.registry().GetUserDataTable();
|
||||
lua_pushlightuserdata(L, this);
|
||||
lua_pushvalue(L, -3);
|
||||
lua_rawset(L, -3);
|
||||
lua_pop(L, 1);
|
||||
// Swap the table and metatable for stack arg purposes
|
||||
lua_insert( L, -2 );
|
||||
lua_setmetatable( L, -2 );
|
||||
}
|
||||
|
||||
void LuaInterface::luaPushObject( LuaState state, const char* sClassName, void *Ptr )
|
||||
{
|
||||
lua_State* L = state();
|
||||
state.registry().GetUserDataTable();
|
||||
lua_pushlightuserdata(L, Ptr);
|
||||
lua_rawget(L,-2);
|
||||
if(lua_isnil(L,-1))
|
||||
{
|
||||
lua_pop(L, 1);
|
||||
luaL_getmetatable( L, sClassName );
|
||||
if (lua_istable( L, -1 ) )
|
||||
{
|
||||
this->luaCreateObject( state, Ptr );
|
||||
}
|
||||
}
|
||||
if(!lua_isuserdata(L,-1))
|
||||
{
|
||||
SGP_THROW(L"Could not create User Data");
|
||||
}
|
||||
lua_insert(L, -2);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
void LuaInterface::luaPushObject( LuaState state, const char* luaName )
|
||||
{
|
||||
LuaInterface::SInterfaceData* iface = this->luaGetInterface();
|
||||
this->luaPushObject(state, iface->ClassHierarchy.front().c_str(), this);
|
||||
if(luaName != NULL)
|
||||
{
|
||||
lua_setglobal( state(), luaName );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#ifndef _LUA_CLASS_INTERFACE_H_
|
||||
#define _LUA_CLASS_INTERFACE_H_
|
||||
|
||||
//#include "Lua Interpreter.h"
|
||||
#include "lua_state.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
#define DECLARE_LUA_CFUNCTION(name) static int name(lua_State* L)
|
||||
#define DEFINE_LUA_CFUNCTION(class_name,name) int class_name::name(lua_State* L)
|
||||
|
||||
class LuaInterface
|
||||
{
|
||||
public:
|
||||
struct SInterfaceData
|
||||
{
|
||||
typedef std::list<LuaAttrib*> tAttribs;
|
||||
typedef std::list<std::string> tClassInterface;
|
||||
tAttribs Attribs;
|
||||
tClassInterface ClassHierarchy;
|
||||
};
|
||||
|
||||
static const char* luaClassName;
|
||||
public:
|
||||
LuaInterface();
|
||||
virtual ~LuaInterface();
|
||||
|
||||
virtual void luaPushObject( LuaState L, const char* luaName = NULL );
|
||||
|
||||
protected:
|
||||
static void luaExportInterface(LuaState L, LuaInterface::SInterfaceData& iface);
|
||||
static SInterfaceData* luaGetExportedInterface( SInterfaceData* iface=NULL);
|
||||
|
||||
virtual SInterfaceData* luaGetInterface();
|
||||
|
||||
void luaPushObject( LuaState L, const char* sClassName, void *Ptr );
|
||||
private:
|
||||
void luaCreateObject( LuaState L, void *Ptr );
|
||||
void* luaObject;
|
||||
|
||||
static LuaAttrib* luaCommonGetSet( LuaState L );
|
||||
static void* luaIsOfType(LuaState L, int index, const char* sClassName);
|
||||
|
||||
// "meta"-interface
|
||||
//static int luaGetObject( lua_State *L);
|
||||
//static int luaSetObject( lua_State *L);
|
||||
DECLARE_LUA_CFUNCTION( luaGetObject );
|
||||
DECLARE_LUA_CFUNCTION( luaSetObject );
|
||||
|
||||
static luaL_Reg s_ClassList[];
|
||||
public:
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
static void luaExportClass( LuaState L )
|
||||
{
|
||||
LuaInterface::SInterfaceData* iface = T::luaGetExportedInterface();
|
||||
LuaInterface::luaExportInterface(L, *iface);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static T* luaGetTypedUserData(LuaState L, int index)
|
||||
{
|
||||
void *ptr = LuaInterface::luaIsOfType(L, index, T::luaClassName);
|
||||
if( !ptr )
|
||||
{
|
||||
luaL_typerror(L(), index, T::luaClassName);
|
||||
}
|
||||
|
||||
T** ppNode = (T**)(ptr);
|
||||
if(ppNode)
|
||||
{
|
||||
return *ppNode;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
class LuaUserObject
|
||||
{
|
||||
public:
|
||||
LuaUserObject(LuaInterface* luaObject=NULL) : _luaObject(luaObject) {};
|
||||
void PushObject(LuaState state, const char* luaName = NULL)
|
||||
{
|
||||
if(_luaObject) _luaObject->luaPushObject(state, luaName);
|
||||
}
|
||||
private:
|
||||
LuaInterface* _luaObject;
|
||||
};
|
||||
|
||||
#ifndef DECLARE_LUA_INTERFACE
|
||||
#define DECLARE_LUA_INTERFACE(BaseClass) \
|
||||
private: \
|
||||
typedef BaseClass tSuperClass; \
|
||||
public: \
|
||||
static const char* luaClassName; \
|
||||
static SInterfaceData* luaGetExportedInterface(SInterfaceData* iface=NULL); \
|
||||
protected: \
|
||||
virtual SInterfaceData* luaGetInterface(); \
|
||||
private: \
|
||||
static SInterfaceData luaInterface;
|
||||
#endif // DECLARE_LUA_INTERFACE
|
||||
|
||||
#ifndef IMPLEMENT_LUA_INTERFACE
|
||||
#define IMPLEMENT_LUA_INTERFACE(className, classLuaName, AttribArray) \
|
||||
const char* className::luaClassName = classLuaName; \
|
||||
LuaInterface::SInterfaceData className::luaInterface; \
|
||||
LuaInterface::SInterfaceData* className::luaGetInterface() \
|
||||
{ \
|
||||
return &(className::luaInterface); \
|
||||
} \
|
||||
LuaInterface::SInterfaceData* className::luaGetExportedInterface(LuaInterface::SInterfaceData* iface) \
|
||||
{ \
|
||||
if(!iface) iface = &(className::luaInterface); \
|
||||
iface->ClassHierarchy.push_back(className::luaClassName); \
|
||||
iface->Attribs.push_back(AttribArray); \
|
||||
return tSuperClass::luaGetExportedInterface( iface ); \
|
||||
}
|
||||
#endif // IMPLEMENT_LUA_INTERFACE
|
||||
|
||||
#endif // _LUA_CLASS_INTERFACE_H_
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "DEBUG.H"
|
||||
#include "lua/lua_function.h"
|
||||
|
||||
template<>
|
||||
LuaFunction& LuaFunction::Param<std::string>(std::string const& par)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
lua_pushstring(_L, par.c_str());
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
LuaFunction& LuaFunction::Param<double>(double const& par)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
lua_pushnumber(_L, par);
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
LuaFunction& LuaFunction::Param<int>(int const& par)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
lua_pushinteger(_L, par);
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
LuaFunction& LuaFunction::Param<unsigned int>(unsigned int const& par)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
lua_pushnumber(_L, (double)par);
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<>
|
||||
LuaFunction& LuaFunction::Param<bool>(bool const& par)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
lua_pushboolean(_L, par);
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
#ifndef _LUA_FUNCTION_H_
|
||||
#define _LUA_FUNCTION_H_
|
||||
|
||||
#include <lua_state.h>
|
||||
#include <lua_table.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
class LuaFunction
|
||||
{
|
||||
public:
|
||||
LuaFunction(LuaState L, const char* function_name)
|
||||
: _function_name(function_name), _L(L()), _counter(0), m_is_function(false)
|
||||
{
|
||||
lua_getglobal(_L, function_name);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
LuaFunction& Param(T const& par);
|
||||
|
||||
template<typename TI, typename TV>
|
||||
LuaFunction& TParam(TI const index, TV const& par)
|
||||
{
|
||||
if(m_is_function || is_function(-2))
|
||||
{
|
||||
if(!_tables.empty())
|
||||
{
|
||||
LuaTable& tab = *_tables.top();
|
||||
tab.setValue(index, par);
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
LuaFunction& TableOpen()
|
||||
{
|
||||
_tables.push(new LuaTable(_L));
|
||||
return *this;
|
||||
}
|
||||
LuaFunction& TableClose()
|
||||
{
|
||||
if(!_tables.empty())
|
||||
{
|
||||
LuaTable* tab = _tables.top();
|
||||
_tables.pop();
|
||||
if(tab) delete tab;
|
||||
_counter++;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool Call(int num_ret)
|
||||
{
|
||||
if(m_is_function || is_function())
|
||||
{
|
||||
if(_tables.empty() && num_ret >= 0)
|
||||
{
|
||||
if( lua_pcall(_L, _counter, num_ret, 0) != 0)
|
||||
{
|
||||
std::string err = lua_tostring(_L, -1);
|
||||
|
||||
std::wstring wstr;
|
||||
convert_string(_function_name, wstr);
|
||||
|
||||
std::wstringstream wss;
|
||||
wss << L"Execution of lua function '" << wstr << L"' failed : ";
|
||||
|
||||
convert_string(err, wstr);
|
||||
wss << wstr;
|
||||
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
bool is_function(int pos=-1)
|
||||
{
|
||||
return m_is_function = lua_isfunction(_L, pos);
|
||||
}
|
||||
private:
|
||||
std::string _function_name;
|
||||
lua_State* _L;
|
||||
std::stack<LuaTable*> _tables;
|
||||
int _counter;
|
||||
bool m_is_function;
|
||||
};
|
||||
|
||||
|
||||
#endif // _LUA_FUNCTION_H_
|
||||
@@ -0,0 +1,293 @@
|
||||
#include "lua/lua_state.h"
|
||||
#include <Debug.h>
|
||||
#include "sgp_logger.h"
|
||||
|
||||
#include <vfs/Core/vfs_string.h>
|
||||
|
||||
LuaState::LuaState(lua_State* state, bool own) : _L(state), _own(own), _registry(state)
|
||||
{
|
||||
}
|
||||
|
||||
LuaState::LuaState() : _L(NULL), _own(true), _registry(NULL)
|
||||
{
|
||||
//_L = lua_open();
|
||||
//_registry._L = _L;
|
||||
}
|
||||
|
||||
LuaState::~LuaState()
|
||||
{
|
||||
}
|
||||
|
||||
void LuaState::init(bool init_libs)
|
||||
{
|
||||
if(!_L)
|
||||
{
|
||||
_L = lua_open();
|
||||
if(init_libs)
|
||||
{
|
||||
luaL_openlibs(_L);
|
||||
}
|
||||
_registry._L = _L;
|
||||
}
|
||||
}
|
||||
|
||||
void LuaState::close()
|
||||
{
|
||||
if(_L && _own)
|
||||
{
|
||||
lua_close(_L);
|
||||
}
|
||||
}
|
||||
|
||||
#include <vfs/Core/vfs_file_raii.h>
|
||||
bool LuaState::EvalFile(const char* filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
vfs::COpenReadFile rfile(filename);
|
||||
vfs::UInt32 size = rfile.file().getSize();
|
||||
std::vector<vfs::Byte> buffer(size+1);
|
||||
rfile.file().read(&buffer[0], size);
|
||||
buffer[size] = 0;
|
||||
return this->EvalString((char*)&buffer[0], size, filename);
|
||||
}
|
||||
catch(std::exception &ex)
|
||||
{
|
||||
SGP_ERROR(ex.what());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LuaState::CallFunction(const char* function_name)
|
||||
{
|
||||
if(function_name)
|
||||
{
|
||||
// call function
|
||||
lua_getglobal(_L, function_name);
|
||||
if(lua_isfunction(_L, -1))
|
||||
{
|
||||
if( lua_pcall(_L, 0, 1, 0) != 0 )
|
||||
{
|
||||
std::string err = lua_tostring(_L, -1);
|
||||
std::wstringstream wss;
|
||||
wss << L"Execution of lua function '" << vfs::String::as_utf16(function_name) << L"' failed : ";
|
||||
wss << vfs::String::as_utf16(err);
|
||||
SGP_THROW(wss.str().c_str());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool LuaState::EvalString(const wchar_t *lua_str, size_t length, const char* id_str)
|
||||
{
|
||||
std::string s = vfs::String::as_utf8(lua_str, length);
|
||||
|
||||
return this->EvalString(s.c_str(), s.length(), id_str);
|
||||
}
|
||||
|
||||
bool LuaState::EvalString(const char *lua_str, size_t length, const char* id_str)
|
||||
{
|
||||
int error;
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
length = strlen(lua_str);
|
||||
}
|
||||
error = luaL_loadbuffer(_L, lua_str, length, id_str) ||
|
||||
lua_pcall(_L, 0, 0, 0);
|
||||
|
||||
if (error)
|
||||
{
|
||||
const char *error = lua_tostring(_L, -1);
|
||||
int len = strlen( error);
|
||||
if (len >= 7 && !strcmp( error + len - 7, "'<eof>'"))
|
||||
{
|
||||
lua_pop(_L, 1); /* pop error message from the stack */
|
||||
return false;
|
||||
}
|
||||
std::string s = lua_tostring(_L, -1);
|
||||
SGP_THROW(s);
|
||||
//printf( "%s\n", lua_tostring(L, -1));
|
||||
//lua_pop(L, 1); /* pop error message from the stack */
|
||||
//return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
||||
LuaState::Registry::Registry(lua_State* L) : _L(L)
|
||||
{
|
||||
}
|
||||
|
||||
void LuaState::Registry::CreateCallbackTable()
|
||||
{
|
||||
lua_getfield(_L, LUA_REGISTRYINDEX, "__CallBackRegistry");
|
||||
if(lua_isnil(_L,-1))
|
||||
{
|
||||
lua_pop(_L,1); // pop 'nil' from stack
|
||||
lua_newtable(_L);
|
||||
lua_setfield(_L,LUA_REGISTRYINDEX,"__CallBackRegistry"); // 'setfield' removes value from stack
|
||||
return;
|
||||
}
|
||||
else if(lua_istable(_L,-1))
|
||||
{
|
||||
lua_pop(_L,1);
|
||||
return;
|
||||
}
|
||||
SGP_THROW(L"Could not create callback registy table");
|
||||
}
|
||||
void LuaState::Registry::GetCallbackTable()
|
||||
{
|
||||
lua_getfield(_L, LUA_REGISTRYINDEX, "__CallBackRegistry");
|
||||
if(!lua_istable(_L,-1))
|
||||
{
|
||||
SGP_THROW("CallBack registry table does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
void LuaState::Registry::SetCallback(const char* callback_name)
|
||||
{
|
||||
// function is at (L, -2)
|
||||
// user data value is at (L, -1)
|
||||
this->GetCallbackTable();
|
||||
lua_pushvalue(_L, -2);
|
||||
lua_rawget(_L, -2);
|
||||
if(!lua_istable(_L, -1))
|
||||
{
|
||||
lua_pop(_L, 1); // remove 'nil'
|
||||
// set new table
|
||||
lua_pushvalue(_L, -2);
|
||||
lua_newtable(_L);
|
||||
lua_rawset(_L, -3);
|
||||
// get table
|
||||
lua_pushvalue(_L, -2);
|
||||
lua_rawget(_L, -2);
|
||||
}
|
||||
if(!lua_istable(_L,-1))
|
||||
{
|
||||
SGP_THROW("Could not create callback");
|
||||
}
|
||||
lua_pushvalue(_L, -4);
|
||||
lua_setfield(_L, -2, callback_name);
|
||||
lua_pop(_L, 4);
|
||||
}
|
||||
void LuaState::Registry::GetCallback(const char* callback_name)
|
||||
{
|
||||
// user data is at (L, -1)
|
||||
this->GetCallbackTable();
|
||||
lua_pushvalue(_L, -2);
|
||||
lua_rawget(_L, -2);
|
||||
if(lua_istable(_L, -1))
|
||||
{
|
||||
lua_getfield(_L, -1, callback_name);
|
||||
if(lua_isfunction(_L, -1))
|
||||
{
|
||||
lua_insert(_L, -4);
|
||||
lua_pop(_L, 3);
|
||||
if(!lua_isfunction(_L,-1))
|
||||
{
|
||||
SGP_THROW("messed up stack");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// no callback defined
|
||||
lua_pop(_L, 4);
|
||||
}
|
||||
// no table created
|
||||
lua_pop(_L, 3); // also pops user data
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void LuaState::Registry::CreateUserDataTable()
|
||||
{
|
||||
lua_getfield(_L, LUA_REGISTRYINDEX, "__UserData");
|
||||
if(lua_isnil(_L,-1))
|
||||
{
|
||||
lua_pop(_L,1); // pop 'nil' from stack
|
||||
lua_newtable(_L);
|
||||
lua_setfield(_L,LUA_REGISTRYINDEX,"__UserData"); // 'setfield' removes value from stack
|
||||
return;
|
||||
}
|
||||
else if(lua_istable(_L,-1))
|
||||
{
|
||||
lua_pop(_L,1);
|
||||
return;
|
||||
}
|
||||
SGP_THROW(L"Could not create User Data registy table");
|
||||
}
|
||||
|
||||
void LuaState::Registry::GetUserDataTable()
|
||||
{
|
||||
lua_getfield(_L, LUA_REGISTRYINDEX, "__UserData");
|
||||
if(!lua_istable(_L,-1))
|
||||
{
|
||||
SGP_THROW("User Data registry table does not exist");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************/
|
||||
|
||||
#include <map>
|
||||
|
||||
class LuaStateManager
|
||||
{
|
||||
public:
|
||||
~LuaStateManager() {
|
||||
_states.clear();
|
||||
};
|
||||
|
||||
static LuaStateManager& instance() {
|
||||
static LuaStateManager lsm;
|
||||
return lsm;
|
||||
};
|
||||
|
||||
LuaState& GetState(lua::State eState) {
|
||||
return _states[eState];
|
||||
}
|
||||
|
||||
private:
|
||||
LuaStateManager() {};
|
||||
static std::map<lua::State, LuaState> _states;
|
||||
};
|
||||
|
||||
std::map<lua::State, LuaState> LuaStateManager::_states;
|
||||
|
||||
|
||||
void LuaState::INIT(lua::State state_id, bool init_libs)
|
||||
{
|
||||
LuaStateManager::instance().GetState(state_id).init(init_libs);
|
||||
}
|
||||
|
||||
LuaState LuaState::INIT(bool init_libs)
|
||||
{
|
||||
LuaState L;
|
||||
L.init(init_libs);
|
||||
return L;
|
||||
}
|
||||
|
||||
void LuaState::CLOSE(lua::State state_id)
|
||||
{
|
||||
LuaStateManager::instance().GetState(state_id).close();
|
||||
}
|
||||
|
||||
void LuaState::CLOSE(LuaState state)
|
||||
{
|
||||
state.close();
|
||||
}
|
||||
|
||||
LuaState LuaState::GET(lua::State state_id)
|
||||
{
|
||||
return LuaStateManager::instance().GetState(state_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
#ifndef _LUA_STATE_H_
|
||||
#define _LUA_STATE_H_
|
||||
|
||||
#include <Lua Interpreter.h>
|
||||
|
||||
namespace lua
|
||||
{
|
||||
enum State
|
||||
{
|
||||
LUA_STATE,
|
||||
LUA_STATE_STRUCTURE,
|
||||
LUA_STATE_GUI,
|
||||
|
||||
LUA_STATE_STRATEGIC_MINES_AND_UNDERGROUND,
|
||||
};
|
||||
};
|
||||
|
||||
class LuaState
|
||||
{
|
||||
class Registry
|
||||
{
|
||||
public:
|
||||
void CreateCallbackTable();
|
||||
void GetCallbackTable();
|
||||
|
||||
void SetCallback(const char* callback_name);
|
||||
void GetCallback(const char* callback_name);
|
||||
|
||||
void CreateUserDataTable();
|
||||
void GetUserDataTable();
|
||||
private:
|
||||
friend class LuaState;
|
||||
Registry(lua_State* L);
|
||||
lua_State* _L;
|
||||
};
|
||||
public:
|
||||
/**
|
||||
* takes over raw lua_State
|
||||
* @param state pointer to lua_State
|
||||
* @param own takes over raw state when true (= closes it)
|
||||
*/
|
||||
LuaState(lua_State* state, bool own=false);
|
||||
|
||||
/**
|
||||
* default ctor, does nothing other than allowing uninitialized variables
|
||||
*/
|
||||
LuaState();
|
||||
|
||||
/**
|
||||
* default dtor
|
||||
*/
|
||||
~LuaState();
|
||||
|
||||
/**
|
||||
* initialize longterm lua state by its ID
|
||||
*/
|
||||
static void INIT(lua::State state_id, bool init_libs);
|
||||
|
||||
/**
|
||||
* initializes and returns shortterm lua state
|
||||
*/
|
||||
static LuaState INIT(bool init_libs=false);
|
||||
|
||||
/**
|
||||
* close longterm lua state
|
||||
*/
|
||||
static void CLOSE(lua::State state_id);
|
||||
|
||||
/**
|
||||
* close shortterm lua state
|
||||
*/
|
||||
static void CLOSE(LuaState state);
|
||||
|
||||
/**
|
||||
* get lua state after it was initialized (right before or in some other place)
|
||||
*/
|
||||
static LuaState GET(lua::State state_id);
|
||||
|
||||
/**
|
||||
* returns raw lua state
|
||||
*/
|
||||
inline lua_State* operator()() { return _L; }
|
||||
|
||||
/**
|
||||
* return registry object associated with this lua state
|
||||
*/
|
||||
inline Registry& registry() { return _registry; }
|
||||
|
||||
/**
|
||||
* loads and evaluates lua file. catches and logs error if file doesn't exist or could not be read.
|
||||
* @return true if file could be loaded and evaluated, false otherwise.
|
||||
*/
|
||||
bool EvalFile(const char* filename);
|
||||
|
||||
/**
|
||||
* evaluate string
|
||||
*/
|
||||
bool EvalString(const char* lua_str, size_t length, const char* id_str);
|
||||
/**
|
||||
* evaluate string
|
||||
*/
|
||||
bool EvalString(const wchar_t* lua_str, size_t length, const char* id_str);
|
||||
|
||||
/**
|
||||
* deprecated (i guess), use LuaFunction instead
|
||||
*/
|
||||
bool CallFunction(const char* function_name);
|
||||
private:
|
||||
/**
|
||||
* creates lua state and initializes additional libraries
|
||||
* @param load_libs opens additional libraries if true
|
||||
*/
|
||||
void init(bool load_libs);
|
||||
|
||||
/**
|
||||
* closes lua state
|
||||
*/
|
||||
void close();
|
||||
private:
|
||||
lua_State* _L;
|
||||
bool _own;
|
||||
Registry _registry;
|
||||
};
|
||||
|
||||
class LuaScopeState
|
||||
{
|
||||
public:
|
||||
LuaState L;
|
||||
|
||||
LuaScopeState(bool init_libs) : L(LuaState::INIT(init_libs))
|
||||
{
|
||||
}
|
||||
|
||||
~LuaScopeState()
|
||||
{
|
||||
LuaState::CLOSE(L);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _LUA_STATE_H_
|
||||
@@ -0,0 +1,341 @@
|
||||
#include "lua/lua_table.h"
|
||||
|
||||
/*
|
||||
* Table constructors
|
||||
*/
|
||||
|
||||
LuaTable::LuaTable(LuaState L)
|
||||
: _L(L)
|
||||
{
|
||||
lua_newtable(_L());
|
||||
_off = -1;
|
||||
}
|
||||
|
||||
LuaTable::LuaTable(LuaState L, int st_off)
|
||||
: _L(L), _off(st_off)
|
||||
{};
|
||||
|
||||
LuaTable::LuaTable(LuaState L, const char* global)
|
||||
: _L(L)
|
||||
{
|
||||
lua_getglobal(_L(), global);
|
||||
_off = -1;
|
||||
};
|
||||
|
||||
LuaTable::LuaTable(LuaTable& table, const char* index)
|
||||
: _off(-1)
|
||||
{
|
||||
_L = table._L;
|
||||
lua_State* L = _L();
|
||||
lua_getfield(L, table._off, index);
|
||||
if(!is_valid())
|
||||
{
|
||||
lua_pop(L,1);
|
||||
}
|
||||
}
|
||||
|
||||
LuaTable::LuaTable(LuaTable& table, int index)
|
||||
: _off(-1)
|
||||
{
|
||||
_L = table._L;
|
||||
lua_State* L = _L();
|
||||
lua_pushinteger(L, index);
|
||||
lua_gettable(L, table._off < 0 ? table._off-1 : table._off);
|
||||
if(!is_valid())
|
||||
{
|
||||
lua_pop(L,1);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<std::string>(const char* index, std::string& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_getfield(L, _off, index);
|
||||
if(lua_isstring(L, -1))
|
||||
{
|
||||
value = lua_tostring(L,-1);
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<double>(const char* index, double& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_getfield(L, _off, index);
|
||||
if(lua_isnumber(L, -1))
|
||||
{
|
||||
value = lua_tonumber(L,-1);
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<int>(const char* index, int& value)
|
||||
{
|
||||
double tmp;
|
||||
if( getValue<double>(index,tmp) )
|
||||
{
|
||||
value = (int)tmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
template<>
|
||||
bool LuaTable::getValue<unsigned int>(const char* index, unsigned int& value)
|
||||
{
|
||||
double tmp;
|
||||
if( getValue<double>(index,tmp) )
|
||||
{
|
||||
value = (unsigned int)tmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<bool>(const char* index, bool& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_getfield(L, _off, index);
|
||||
if(lua_isboolean(L, -1))
|
||||
{
|
||||
value = lua_toboolean(L,-1) != 0;
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/////
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<std::string>(int index, std::string& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_pushinteger(L, index);
|
||||
lua_gettable(L, _off < 0 ? _off-1 : _off);
|
||||
if(lua_isstring(L, -1))
|
||||
{
|
||||
value = lua_tostring(L,-1);
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<double>(int index, double& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_pushinteger(L, index);
|
||||
lua_gettable(L, _off < 0 ? _off-1 : _off);
|
||||
if(lua_isnumber(L, -1))
|
||||
{
|
||||
value = lua_tonumber(L,-1);
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<int>(int index, int& value)
|
||||
{
|
||||
double tmp;
|
||||
if( getValue<double>(index,tmp) )
|
||||
{
|
||||
value = (int)tmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
template<>
|
||||
bool LuaTable::getValue<unsigned int>(int index, unsigned int& value)
|
||||
{
|
||||
double tmp;
|
||||
if( getValue<double>(index,tmp) )
|
||||
{
|
||||
value = (unsigned int)tmp;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::getValue<bool>(int index, bool& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
lua_pushinteger(L, index);
|
||||
lua_gettable(L, _off < 0 ? _off-1 : _off);
|
||||
if(lua_isboolean(L, -1))
|
||||
{
|
||||
value = lua_toboolean(L,-1) != 0;
|
||||
lua_pop(L,1);
|
||||
return true;
|
||||
}
|
||||
lua_pop(L,1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<std::string>(const char* index, std::string const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushstring(L, index);
|
||||
lua_pushstring(L, value.c_str());
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<double>(const char* index, double const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushstring(L, index);
|
||||
lua_pushnumber(L, value);
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<int>(const char* index, int const& value)
|
||||
{
|
||||
return setValue<double>(index, (double)value);
|
||||
}
|
||||
template<>
|
||||
bool LuaTable::setValue<unsigned int>(const char* index, unsigned int const& value)
|
||||
{
|
||||
return setValue<double>(index, (double)value);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<bool>(const char* index, bool const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushstring(L, index);
|
||||
lua_pushboolean(L, value);
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<std::string>(int index, std::string const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushinteger(L, index);
|
||||
lua_pushstring(L, value.c_str());
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<double>(int index, double const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushinteger(L, index);
|
||||
lua_pushnumber(L, value);
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<int>(int index, int const& value)
|
||||
{
|
||||
return setValue<double>(index, (double)value);
|
||||
}
|
||||
template<>
|
||||
bool LuaTable::setValue<unsigned int>(int index, unsigned int const& value)
|
||||
{
|
||||
return setValue<double>(index, (double)value);
|
||||
}
|
||||
|
||||
template<>
|
||||
bool LuaTable::setValue<bool>(int index, bool const& value)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_State* L = _L();
|
||||
|
||||
lua_pushinteger(L, index);
|
||||
lua_pushboolean(L, value);
|
||||
lua_rawset(L, _off < 0 ? _off-2 : _off);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
int LuaTable::length()
|
||||
{
|
||||
return (int)lua_objlen(_L(), _off);
|
||||
}
|
||||
|
||||
bool LuaTable::is_valid()
|
||||
{
|
||||
if(lua_istable(_L(), _off))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
#ifndef _LUA_TABLE_H_
|
||||
#define _LUA_TABLE_H_
|
||||
|
||||
#include "lua/lua_state.h"
|
||||
|
||||
class LuaTable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Create new table
|
||||
*/
|
||||
LuaTable(LuaState L);
|
||||
|
||||
/**
|
||||
* Bind to table at stack offset 'st_off'
|
||||
*/
|
||||
LuaTable(LuaState L, int st_off);
|
||||
|
||||
/**
|
||||
* Bind to table with global name 'global'
|
||||
*/
|
||||
LuaTable(LuaState L, const char* global);
|
||||
|
||||
/**
|
||||
* Bind to table value 'index' of table 'table'
|
||||
*/
|
||||
LuaTable(LuaTable& table, const char* index);
|
||||
|
||||
/**
|
||||
* Bind to table value 'index' of table 'table'
|
||||
*/
|
||||
LuaTable(LuaTable& table, int index);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* get value at given index; default implementation for standard types exists
|
||||
* @return true if value at index exists and has required type, false otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
bool getValue(const char* index, T& value);
|
||||
|
||||
/**
|
||||
* get value at given index; default implementation for standard types exists
|
||||
* @return true if value at index exists and has required type, false otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
bool getValue(int index, T& value);
|
||||
|
||||
/**
|
||||
* If value has not standard type, then the default implementation expects it to be user data.
|
||||
* The userdata object itself must inherit from the 'LuaInterface' class.
|
||||
* @return object if it has correct type, NULL otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
T* getValue(const char* index)
|
||||
{
|
||||
if(is_valid())
|
||||
{
|
||||
lua_getfield(_L(), _off, index);
|
||||
T* value = LuaInterface::luaGetTypedUserData<T>(_L, -1);
|
||||
return value;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* set value at given index
|
||||
* @return false if table object is invalid, true otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
bool setValue(const char* index, T const& value);
|
||||
|
||||
/**
|
||||
* set value at given index
|
||||
* @return false if table object is invalid, true otherwise
|
||||
*/
|
||||
template<typename T>
|
||||
bool setValue(int index, T const& value);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* is it a table at offset '_off'
|
||||
*/
|
||||
bool is_valid();
|
||||
|
||||
/**
|
||||
* returns size of table as determined by the "#" operator
|
||||
*/
|
||||
int length();
|
||||
|
||||
private:
|
||||
LuaState _L;
|
||||
int _off;
|
||||
};
|
||||
|
||||
/////////////////////
|
||||
// default implementation for 'getValue(const char*, xxx)'
|
||||
template<> bool LuaTable::getValue<std::string> (const char* index, std::string& value);
|
||||
template<> bool LuaTable::getValue<double> (const char* index, double& value);
|
||||
template<> bool LuaTable::getValue<int> (const char* index, int& value);
|
||||
template<> bool LuaTable::getValue<unsigned int>(const char* index, unsigned int& value);
|
||||
template<> bool LuaTable::getValue<bool> (const char* index, bool& value);
|
||||
|
||||
// default implementation for 'getValue(int, xxx)'
|
||||
template<> bool LuaTable::getValue<std::string> (int index, std::string& value);
|
||||
template<> bool LuaTable::getValue<double> (int index, double& value);
|
||||
template<> bool LuaTable::getValue<int> (int index, int& value);
|
||||
template<> bool LuaTable::getValue<unsigned int>(int index, unsigned int& value);
|
||||
template<> bool LuaTable::getValue<bool> (int index, bool& value);
|
||||
|
||||
/////////////////////
|
||||
// default implementation for 'setValue(const char*, xxx)'
|
||||
template<> bool LuaTable::setValue<std::string> (const char* index, std::string const& value);
|
||||
template<> bool LuaTable::setValue<double> (const char* index, double const& value);
|
||||
template<> bool LuaTable::setValue<int> (const char* index, int const& value);
|
||||
template<> bool LuaTable::setValue<unsigned int>(const char* index, unsigned int const& value);
|
||||
template<> bool LuaTable::setValue<bool> (const char* index, bool const& value);
|
||||
|
||||
// default implementation for 'setValue(int*, xxx)'
|
||||
template<> bool LuaTable::setValue<std::string> (int index, std::string const& value);
|
||||
template<> bool LuaTable::setValue<double> (int index, double const& value);
|
||||
template<> bool LuaTable::setValue<int> (int index, int const& value);
|
||||
template<> bool LuaTable::setValue<unsigned int>(int index, unsigned int const& value);
|
||||
template<> bool LuaTable::setValue<bool> (int index, bool const& value);
|
||||
|
||||
#endif // _LUA_TABLE_H_
|
||||
Reference in New Issue
Block a user