📄 lua_true.c
字号:
/****************************************************************************
** **
** LuAllegro library - Lua port of Allegro **
** Copyright (C) 2005 Peter Jamroz **
** e-mail: peterjam at poczta dot onet dot pl **
** **
** Permission to use, copy, modify, publish this software **
** is hereby granted to any person obtaining a copy of this software, **
** FREE OF CHARGE, **
** under the following conditions: **
** **
** 1: The above copyright notice and this permission notice shall be **
** included in all copies or substantial portions of the Software. **
** **
** 2: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, **
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF **
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.**
** IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY **
** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, **
** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE **
** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **
** **
****************************************************************************/
#include <allegro.h>
#include "lua_aleg.h"
#include "lua_true.h"
//---------------------------------------------------------------------------------------------
//------ Truecolor pixel formats --------------------------------------------------------------
//---------------------------------------------------------------------------------------------
#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
//------------------------------------------------------------------------------------------
//int geta(int c);
int l_geta(lua_State* L)
{
int color = (int) lua_tonumber(L,1);
lua_pushnumber(L,geta(color));
return 1;
}
//------------------------------------------------------------------------------------------
//int getr(int c);
int l_getr(lua_State* L)
{
int color = (int) lua_tonumber(L,1);
lua_pushnumber(L,getr(color));
return 1;
}
//------------------------------------------------------------------------------------------
//int getg(int c);
int l_getg(lua_State* L)
{
int color = (int) lua_tonumber(L,1);
lua_pushnumber(L,getg(color));
return 1;
}
//------------------------------------------------------------------------------------------
//int getb(int c);
int l_getb(lua_State* L)
{
int color = (int) lua_tonumber(L,1);
lua_pushnumber(L,getb(color));
return 1;
}
//------------------------------------------------------------------------------------------
//r,g,b,a=get_rgba(color)
int l_get_rgba(lua_State* L)
{
int color = (int) lua_tonumber(L,1);
lua_pushnumber(L,getr(color));
lua_pushnumber(L,getg(color));
lua_pushnumber(L,getb(color));
lua_pushnumber(L,geta(color));
return 4;
}
//------------------------------------------------------------------------------------------
//int makecol(int r, int g, int b);
int l_makecol(lua_State* L)
{
int r = (int) lua_tonumber(L,1);
int g = (int) lua_tonumber(L,2);
int b = (int) lua_tonumber(L,3);
lua_pushnumber(L,makecol(r,g,b));
return 1;
}
//------------------------------------------------------------------------------------------
//int makeacol(int r, int g, int b, int a);
int l_makeacol(lua_State* L)
{
int r = (int) lua_tonumber(L,1);
int g = (int) lua_tonumber(L,2);
int b = (int) lua_tonumber(L,3);
int a = (int) lua_tonumber(L,3);
lua_pushnumber(L,makeacol(r,g,b,a));
return 1;
}
//------------------------------------------------------------------------------------------
int l_palette_color(lua_State* L)
{
int index= (int) lua_tonumber(L,1);
index= max(0,min(255,index));
lua_pushnumber(L,palette_color[index]);
return 1;
}
//------------------------------------------------------------------------------------------
static const struct luaL_reg allegro_true_lib [] = {
{"geta", l_geta},
{"getr", l_getr},
{"getg", l_getg},
{"getb", l_getb},
{"get_rgba", l_get_rgba},
{"makecol", l_makecol},
{"makeacol", l_makeacol},
{"palette_color", l_palette_color},
{NULL, NULL} /* sentinel */
};
//-----------------------------------------------------------------------------------------------
int luaopen_allegro_true(lua_State *L)
{
luaL_openlib(L, "allegro", allegro_true_lib, 0);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -