mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
Added LUA log comments APIs
This commit is contained in:
@@ -99,6 +99,7 @@ set(RETROFE_HEADERS
|
|||||||
"${RETROFE_DIR}/Source/Lua/Lua.h"
|
"${RETROFE_DIR}/Source/Lua/Lua.h"
|
||||||
"${RETROFE_DIR}/Source/Lua/LuaDisplay.h"
|
"${RETROFE_DIR}/Source/Lua/LuaDisplay.h"
|
||||||
"${RETROFE_DIR}/Source/Lua/LuaImage.h"
|
"${RETROFE_DIR}/Source/Lua/LuaImage.h"
|
||||||
|
"${RETROFE_DIR}/Source/Lua/LuaLog.h"
|
||||||
"${RETROFE_DIR}/Source/RetroFE.h"
|
"${RETROFE_DIR}/Source/RetroFE.h"
|
||||||
"${RETROFE_DIR}/Source/SDL.h"
|
"${RETROFE_DIR}/Source/SDL.h"
|
||||||
"${RETROFE_DIR}/Source/Version.h"
|
"${RETROFE_DIR}/Source/Version.h"
|
||||||
@@ -114,6 +115,7 @@ set(RETROFE_SOURCES
|
|||||||
"${RETROFE_DIR}/Source/Lua/Lua.cpp"
|
"${RETROFE_DIR}/Source/Lua/Lua.cpp"
|
||||||
"${RETROFE_DIR}/Source/Lua/LuaDisplay.cpp"
|
"${RETROFE_DIR}/Source/Lua/LuaDisplay.cpp"
|
||||||
"${RETROFE_DIR}/Source/Lua/LuaImage.cpp"
|
"${RETROFE_DIR}/Source/Lua/LuaImage.cpp"
|
||||||
|
"${RETROFE_DIR}/Source/Lua/LuaLog.cpp"
|
||||||
"${RETROFE_DIR}/Source/Main.cpp"
|
"${RETROFE_DIR}/Source/Main.cpp"
|
||||||
"${RETROFE_DIR}/Source/RetroFE.cpp"
|
"${RETROFE_DIR}/Source/RetroFE.cpp"
|
||||||
"${RETROFE_DIR}/Source/SDL.cpp"
|
"${RETROFE_DIR}/Source/SDL.cpp"
|
||||||
|
|||||||
48
RetroFE/Source/Lua/LuaLog.cpp
Normal file
48
RetroFE/Source/Lua/LuaLog.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#include "LuaLog.h"
|
||||||
|
#include "../Utility/Log.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int LuaLog::debug(lua_State *l)
|
||||||
|
{
|
||||||
|
std::string message = luaL_checkstring(l, 1);
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_DEBUG, "Script", message);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaLog::info(lua_State *l)
|
||||||
|
{
|
||||||
|
std::string message = luaL_checkstring(l, 1);
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Script", message);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaLog::warning(lua_State *l)
|
||||||
|
{
|
||||||
|
std::string message = luaL_checkstring(l, 1);
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_WARNING, "Script", message);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaLog::notice(lua_State *l)
|
||||||
|
{
|
||||||
|
std::string message = luaL_checkstring(l, 1);
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_NOTICE, "Script", message);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int LuaLog::error(lua_State *l)
|
||||||
|
{
|
||||||
|
std::string message = luaL_checkstring(l, 1);
|
||||||
|
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "Script", message);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "Graphics/Component/Component.h"
|
#include "Graphics/Component/Component.h"
|
||||||
#include "Lua/LuaDisplay.h"
|
#include "Lua/LuaDisplay.h"
|
||||||
#include "Lua/LuaImage.h"
|
#include "Lua/LuaImage.h"
|
||||||
|
#include "Lua/LuaLog.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux
|
||||||
@@ -47,57 +48,6 @@ static int lua_registerOnInit(lua_State *l)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
Image *i = NULL;
|
|
||||||
static int lua_imageCreate(lua_State *l)
|
|
||||||
{
|
|
||||||
std::string filename = lua_tostring(l, 1);
|
|
||||||
i = new Image(filename);
|
|
||||||
i->Initialize();
|
|
||||||
lua_pushinteger(l, (int)i);
|
|
||||||
components[i] = i;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_imageDelete(lua_State *l)
|
|
||||||
{
|
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
|
||||||
if(components.find(i) != components.end()) {
|
|
||||||
components.erase(i);
|
|
||||||
}
|
|
||||||
i->deInitialize();
|
|
||||||
delete i;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_imageSetSize(lua_State *l)
|
|
||||||
{
|
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
|
||||||
i->info.width = (int)lua_tointeger(l, 2);
|
|
||||||
i->info.height = (int)lua_tointeger(l, 3);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_imageSetPosition(lua_State *l)
|
|
||||||
{
|
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
|
||||||
i->info.x = (int)lua_tointeger(l, 2);
|
|
||||||
i->info.y = (int)lua_tointeger(l, 3);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_imageSetRotate(lua_State *l)
|
|
||||||
{
|
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
|
||||||
i->info.rotate = (float)lua_tonumber(l, 2);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
static int lua_imageSetAlpha(lua_State *l)
|
|
||||||
{
|
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
|
||||||
i->info.alpha = (float)lua_tonumber(l, 2);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int lua_imageAnimate(lua_State *l)
|
static int lua_imageAnimate(lua_State *l)
|
||||||
{
|
{
|
||||||
Image *i = (Image *)lua_tointeger(l, 1);
|
Image *i = (Image *)lua_tointeger(l, 1);
|
||||||
@@ -142,7 +92,7 @@ static int lua_imageAddAnimation(lua_State *l)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const luaL_Reg luaImageFuncs[] = {
|
const luaL_Reg RetroFE::luaImageFuncs[] = {
|
||||||
// Creation
|
// Creation
|
||||||
{"create", LuaImage::create},
|
{"create", LuaImage::create},
|
||||||
{"loadFile", LuaImage::loadFile},
|
{"loadFile", LuaImage::loadFile},
|
||||||
@@ -184,6 +134,14 @@ const luaL_Reg RetroFE::luaDisplayFuncs[] = {
|
|||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const luaL_Reg RetroFE::luaLogFuncs[] = {
|
||||||
|
{"debug", LuaLog::debug},
|
||||||
|
{"info", LuaLog::info},
|
||||||
|
{"notice", LuaLog::notice},
|
||||||
|
{"warning", LuaLog::warning},
|
||||||
|
{"error", LuaLog::error},
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
void RetroFE::initializeLua()
|
void RetroFE::initializeLua()
|
||||||
{
|
{
|
||||||
@@ -192,18 +150,24 @@ void RetroFE::initializeLua()
|
|||||||
|
|
||||||
lua_newtable(lua_.state);
|
lua_newtable(lua_.state);
|
||||||
luaL_setfuncs (lua_.state, luaDisplayFuncs, 0);
|
luaL_setfuncs (lua_.state, luaDisplayFuncs, 0);
|
||||||
lua_pushvalue(lua_.state,-1);
|
lua_pushvalue(lua_.state, -1);
|
||||||
lua_setglobal(lua_.state, "display");
|
lua_setglobal(lua_.state, "display");
|
||||||
|
|
||||||
lua_newtable(lua_.state);
|
lua_newtable(lua_.state);
|
||||||
luaL_setfuncs (lua_.state, luaImageFuncs, 0);
|
luaL_setfuncs (lua_.state, luaImageFuncs, 0);
|
||||||
lua_pushvalue(lua_.state,-1);
|
lua_pushvalue(lua_.state, -1);
|
||||||
lua_setglobal(lua_.state, "image");
|
lua_setglobal(lua_.state, "image");
|
||||||
|
|
||||||
|
lua_newtable(lua_.state);
|
||||||
|
luaL_setfuncs (lua_.state, luaLogFuncs, 0);
|
||||||
|
lua_pushvalue(lua_.state, -1);
|
||||||
|
lua_setglobal(lua_.state, "log");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RetroFE::reloadLuaScripts()
|
void RetroFE::reloadLuaScripts()
|
||||||
{
|
{
|
||||||
std::string path = config_.absolutePath + "layouts/LUATest/Page.lua";
|
std::string path = config_.absolutePath + "/layouts/LUATest/Page.lua";
|
||||||
luaL_loadfile(lua_.state, path.c_str());
|
luaL_loadfile(lua_.state, path.c_str());
|
||||||
lua_pcall(lua_.state, 0, LUA_MULTRET, 0);
|
lua_pcall(lua_.state, 0, LUA_MULTRET, 0);
|
||||||
}
|
}
|
||||||
@@ -273,4 +237,4 @@ void RetroFE::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,4 +34,6 @@ private:
|
|||||||
Configuration &config_;
|
Configuration &config_;
|
||||||
Lua lua_;
|
Lua lua_;
|
||||||
static const luaL_Reg luaDisplayFuncs[];
|
static const luaL_Reg luaDisplayFuncs[];
|
||||||
|
static const luaL_Reg luaLogFuncs[];
|
||||||
|
static const luaL_Reg luaImageFuncs[];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user