-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathluaCBTexture.cpp
More file actions
134 lines (94 loc) · 3.16 KB
/
luaCBTexture.cpp
File metadata and controls
134 lines (94 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Author: Greg "fugue" Santucci, 2011
// Email: thecodewitch@gmail.com
// Web: http://createuniverses.blogspot.com/
#include "luaCB.h"
int luaCBTextureNew(lua_State * L)
{
// return the GL index of the texture and a pointer to the QImage itself.
PraxisTexture ** c = (PraxisTexture **)lua_newuserdata(L, sizeof(PraxisTexture *));
*c = new PraxisTexture();
luaL_getmetatable(L, "LiveCode.texture");
lua_setmetatable(L, -2);
return 1;
}
int luaCBTextureGC(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
delete c;
return 0;
}
int luaCBTextureClear(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
c->Clear(0,0,0);
return 0;
}
int luaCBTextureSelect(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
glBindTexture(GL_TEXTURE_2D, c->nTextureID);
return 0;
}
int luaCBTextureUpdate(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
c->UpdateTexture();
return 0;
}
int luaCBTextureBegin(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
c->Begin();
return 0;
}
int luaCBTextureEnd(lua_State * L)
{
int n = lua_gettop(L);
if(n!=1) luaL_error(L, "1 argument expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
c->End();
return 0;
}
int luaCBTextureSetRenderFunction(lua_State * L)
{
int n = lua_gettop(L);
if(n!=2) luaL_error(L, "2 arguments expected.");
PraxisTexture * c = *(PraxisTexture **)luaL_checkudata(L, 1, "LiveCode.texture");
std::string sRenderFunction = luaL_checkstring(L, 2);
c->sRenderFunction = sRenderFunction;
return 0;
}
void luaInitCallbacksTextureLib()
{
const struct luaL_Reg lua_texturelib [] = {
{"new", luaCBTextureNew},
{"clear", luaCBTextureClear},
{"select", luaCBTextureSelect},
{"update", luaCBTextureUpdate},
{"setRenderFn", luaCBTextureSetRenderFunction},
{"beginDrawing", luaCBTextureBegin},
{"endDrawing", luaCBTextureEnd},
{NULL, NULL}
};
// Lua 5.1:
//luaL_register(g_pLuaState, "texture", lua_texturelib);
// Lua 5.2:
lua_newtable(g_pLuaState);
luaL_setfuncs (g_pLuaState,lua_texturelib,0);
lua_pushvalue(g_pLuaState,-1);
lua_setglobal(g_pLuaState,"texture");
luaL_newmetatable(g_pLuaState, "LiveCode.texture");
lua_pushstring(g_pLuaState, "__gc");
lua_pushcfunction(g_pLuaState, luaCBTextureGC);
lua_settable(g_pLuaState, -3);
}