Mercurial > mm7
annotate LuaVM.cpp @ 2331:9551756f46c4
Moving functions out of mm7_6.cpp into appropriate classes as static methods or free functions
author | Grumpy7 |
---|---|
date | Wed, 02 Apr 2014 01:21:05 +0200 |
parents | aff7a7b072b7 |
children | f4af3b203f65 |
rev | line source |
---|---|
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
|
1 #define _CRT_SECURE_NO_WARNINGS |
2052 | 2 #include "LuaVM.h" |
3 #include "lib/lua/lua.h" | |
4 #include "Log.h" | |
5 #include "OSAPI.h" | |
6 | |
7 extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module | |
2057 | 8 extern "C" int luaopen_Player(lua_State *L); // declare the wrapped module |
2052 | 9 |
10 LuaVM *lua = nullptr; | |
11 | |
12 void LuaVM::Initialize() | |
13 { | |
14 if (L) | |
15 Log::Warning(L"Overwriting previous Lua state"); | |
16 | |
17 L = luaL_newstate(); | |
18 if (!L) | |
19 Log::Warning(L"Error creating Lua context.\n"); | |
20 | |
21 // open default lua libs | |
22 luaL_openlibs(L); | |
23 | |
24 // open each cxx module | |
25 luaopen_UIControl(L); | |
26 | |
27 //if ( luaL_dofile(L,GetScriptFileLocation("script.lua"))) | |
28 // Log::Warning(L"Error opening script.lua\n"); | |
29 } | |
30 | |
31 bool LuaVM::DoFile(const char *filename) | |
32 { | |
33 if (luaL_dofile(L, GetScriptFileLocation(filename))) | |
34 { | |
35 Log::Warning(L"Error opening script %s", filename); | |
36 return false; | |
37 } | |
38 return true; | |
39 } | |
40 | |
41 const char *LuaVM::GetScriptFileLocation(const char *script_name) | |
42 { | |
43 static DWORD tls_index = TlsAlloc(); | |
44 | |
45 auto buf = (char *)TlsGetValue(tls_index); | |
46 if (!buf) | |
47 { | |
48 buf = new char[1024]; | |
49 TlsSetValue(tls_index, buf); | |
50 } | |
51 | |
52 strcpy(buf, "data/scripts/lua/core/"); | |
53 strcat(buf, script_name); | |
54 return buf; | |
55 } |