# HG changeset patch # User Ritor1 # Date 1385696735 -21600 # Node ID 29e16f184db884c0c8a122057489599eee46065f # Parent bf89a2e9eea19d61b2b0df2084ae2425b33b58fa Add LuaClass.h diff -r bf89a2e9eea1 -r 29e16f184db8 LuaClass.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LuaClass.h Fri Nov 29 09:45:35 2013 +0600 @@ -0,0 +1,46 @@ +#pragma once + +#include +#include +#include "OSAPI.h" + +extern "C" int luaopen_UIControl(lua_State *L); // declare the wrapped module + +class LuaVM +{ + public: + void Initialize() + { + 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"); + // все нужные cxx + luaopen_UIControl(L); + } + + bool DoFile(const char *filename) + { + if (luaL_dofile(L, GetScriptFileLocation(filename))) + { + Log::Warning(L"Error opening %s", filename); + return 1; + } + return 0; + } + + protected: + lua_State *L; + + const char *GetScriptFileLocation(const char *script_name) + { + static char buf[2048]; + strcpy(buf, "Data/scripts/lua/core/"); + strcat(buf, script_name); + return buf; + } +}; + +extern LuaVM *pMM_lua; \ No newline at end of file