changeset 2050:bf89a2e9eea1

LuaClass.h
author Ritor1
date Fri, 29 Nov 2013 01:16:48 +0600
parents 73ee77d482f8
children 29e16f184db8
files Build/Visual Studio 2012/World of Might and Magic.vcxproj Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters Events.cpp mm7_2.cpp
diffstat 4 files changed, 14 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Thu Nov 28 21:49:06 2013 +0600
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Fri Nov 29 01:16:48 2013 +0600
@@ -325,6 +325,7 @@
     <ClInclude Include="..\..\Lights.h" />
     <ClInclude Include="..\..\LOD.h" />
     <ClInclude Include="..\..\Log.h" />
+    <ClInclude Include="..\..\LuaClass.h" />
     <ClInclude Include="..\..\MapInfo.h" />
     <ClInclude Include="..\..\MM7.h" />
     <ClInclude Include="..\..\mm7_data.h" />
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Thu Nov 28 21:49:06 2013 +0600
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Fri Nov 29 01:16:48 2013 +0600
@@ -593,6 +593,7 @@
     <ClInclude Include="..\..\TestClass.h" />
     <ClInclude Include="..\..\OurMath.h" />
     <ClInclude Include="..\..\Timer.h" />
+    <ClInclude Include="..\..\LuaClass.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\lib\legacy_dx\d3dvec.inl">
--- a/Events.cpp	Thu Nov 28 21:49:06 2013 +0600
+++ b/Events.cpp	Fri Nov 29 01:16:48 2013 +0600
@@ -33,6 +33,7 @@
 #include "Log.h"
 #include "MM7.h"
 #include "Level/Decoration.h"
+#include "LuaClass.h"
 
 
 
@@ -428,6 +429,11 @@
   v133 = 0;
   EvtTargetObj = targetObj;
   dword_5B65C4_cancelEventProcessing = 0;
+  if ( uEventID == 114 )
+  {
+    if ( pMM_lua->DoFile("out01.lua") )
+      Log::Warning(L"Error opening out01.lua\n");
+  }
   if ( !uEventID )
     {
     if ( !GameUI_Footer_TimeLeft )
--- a/mm7_2.cpp	Thu Nov 28 21:49:06 2013 +0600
+++ b/mm7_2.cpp	Fri Nov 29 01:16:48 2013 +0600
@@ -69,13 +69,15 @@
 #include "Level/Decoration.h"
 
 #include "lib/lua/lua.h"
-#include "TestClass.h"
+#include "LuaClass.h"
 
 int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam);
 int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4);
 bool __fastcall FindMM7CD(HWND hWnd, char *pCDDrive);
 bool __fastcall Initialize(HINSTANCE hInst, char *pCmdLine);
 
+class LuaVM *pMM_lua;
+
 //----- (004A1780) mm6_chinese---------------------------------------------
 __int64 fixpoint_div(int a1, int a2)
 {
@@ -4310,21 +4312,6 @@
 
 
 
-const char *GetScriptFileLocation(const char *script_name)
-{
-  static char buf[2048];
-  strcpy(buf, "Data/scripts/lua/core/");
-  strcat(buf, script_name);
-  return buf;
-}
-
-
-extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module
-void LoadLuaSWIGLibraries(lua_State *L)
-{
-  luaopen_UIControl(L);
-}
-
 //----- (00462C94) --------------------------------------------------------
 bool MM_Main(const wchar_t *pCmdLine)
 {
@@ -4333,21 +4320,8 @@
   char test[1024];
   sprintfex(test, "^Pi[%s]: знахар^R[ь;ка;]", "Золтан");
 
-  char dir[256];
-  GetCurrentDirectoryA(256, dir);
-
-  lua_State *L = luaL_newstate();
-  if ( L == NULL )
-    Log::Warning(L"Error creating Lua context.\n");
-  luaL_openlibs(L);
-  if ( luaL_dofile(L,GetScriptFileLocation("script.lua")))
-    Log::Warning(L"Error opening script.lua\n");
-
-  LoadLuaSWIGLibraries(L);
-  
-  if (luaL_dofile(L,GetScriptFileLocation("UIControl.lua")))
-    Log::Warning(L"unable to load UIControl.lua\n");
-  //lua_close(l);
+  pMM_lua = new LuaVM;
+  pMM_lua->Initialize();
 
   bool bNoMargareth = false;
   if (pCmdLine && *pCmdLine)
@@ -4527,7 +4501,7 @@
         AIL_redbook_play(pAudioPlayer->hAILRedbook, startms + 1, end_ms);
       }
     }
-  lua_close(L);
+  //lua_close(L);
   pGame->Deinitialize();
   return 1;
 }