Mercurial > mm7
annotate LuaVM.cpp @ 2422:bb1273b1b9b6
//Uninitialized memory access
author | Ritor1 |
---|---|
date | Wed, 23 Jul 2014 01:18:24 +0600 |
parents | f4af3b203f65 |
children |
rev | line source |
---|---|
2415 | 1 #define _CRTDBG_MAP_ALLOC |
2 #include <stdlib.h> | |
3 #include <crtdbg.h> | |
4 | |
2253
aff7a7b072b7
adding _CRT_SECURE_NO_WARNINGS to get rid of a few hundrer annoying warnings + adding count parameter to swprintf
Grumpy7
parents:
2057
diff
changeset
|
5 #define _CRT_SECURE_NO_WARNINGS |
2052 | 6 #include "LuaVM.h" |
7 #include "lib/lua/lua.h" | |
8 #include "Log.h" | |
9 #include "OSAPI.h" | |
10 | |
11 extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module | |
2057 | 12 extern "C" int luaopen_Player(lua_State *L); // declare the wrapped module |
2052 | 13 |
14 LuaVM *lua = nullptr; | |
15 | |
16 void LuaVM::Initialize() | |
17 { | |
18 if (L) | |
19 Log::Warning(L"Overwriting previous Lua state"); | |
20 | |
21 L = luaL_newstate(); | |
22 if (!L) | |
23 Log::Warning(L"Error creating Lua context.\n"); | |
24 | |
25 // open default lua libs | |
26 luaL_openlibs(L); | |
27 | |
28 // open each cxx module | |
29 luaopen_UIControl(L); | |
30 | |
31 //if ( luaL_dofile(L,GetScriptFileLocation("script.lua"))) | |
32 // Log::Warning(L"Error opening script.lua\n"); | |
33 } | |
34 | |
35 bool LuaVM::DoFile(const char *filename) | |
36 { | |
37 if (luaL_dofile(L, GetScriptFileLocation(filename))) | |
38 { | |
39 Log::Warning(L"Error opening script %s", filename); | |
40 return false; | |
41 } | |
42 return true; | |
43 } | |
44 | |
45 const char *LuaVM::GetScriptFileLocation(const char *script_name) | |
46 { | |
47 static DWORD tls_index = TlsAlloc(); | |
48 | |
49 auto buf = (char *)TlsGetValue(tls_index); | |
50 if (!buf) | |
51 { | |
52 buf = new char[1024]; | |
53 TlsSetValue(tls_index, buf); | |
54 } | |
55 | |
56 strcpy(buf, "data/scripts/lua/core/"); | |
57 strcat(buf, script_name); | |
58 return buf; | |
59 } |