Mercurial > mm7
changeset 2051:29e16f184db8
Add LuaClass.h
author | Ritor1 |
---|---|
date | Fri, 29 Nov 2013 09:45:35 +0600 |
parents | bf89a2e9eea1 |
children | 71a814f4482a 95e9a5141338 |
files | LuaClass.h |
diffstat | 1 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 <lib/lua/lua.h> +#include <Log.h> +#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