aboutsummaryrefslogtreecommitdiff
path: root/src/client/lua_api/video/itexture.cpp
diff options
context:
space:
mode:
authorAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
committerAlexander Pickering <alex@cogarr.net>2018-06-23 06:52:55 -0600
commite6faff1394864a1fe0d517584d1c104997dff39f (patch)
treed7956fc8aabef903f354578d69d4d7fdf64ec928 /src/client/lua_api/video/itexture.cpp
parent1aaa348ac080c97c0aeb0a02146ae26b74add5a1 (diff)
parent9fa5dcc9310a8c6ff8c77a47a86303f7b950dcf3 (diff)
downloadbrokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.gz
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.tar.bz2
brokengine-e6faff1394864a1fe0d517584d1c104997dff39f.zip
Merge branch 'master' of ssh://cogarr.net:43/home/git/brokengine
Diffstat (limited to 'src/client/lua_api/video/itexture.cpp')
-rw-r--r--src/client/lua_api/video/itexture.cpp37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp
index a7f4652..42de1bd 100644
--- a/src/client/lua_api/video/itexture.cpp
+++ b/src/client/lua_api/video/itexture.cpp
@@ -14,20 +14,42 @@ using namespace video;
extern IrrlichtDevice* device;
extern IVideoDriver* driver;
-//newtexture(string name,IImage* image)
+//newtexture(string name,{image}) -> {texture}
int newitexture(lua_State* L){
+ //printf("About to create new texture\n");
+ lua_getfield(L,-1,"image");//"name",{image},image*
IImage* im = (IImage*) lua_touserdata(L,-1);
- lua_pop(L,1);
+ lua_pop(L,2);//"name"
const char* name = lua_tostring(L,-1);
- lua_pop(L,1);
+ lua_pop(L,1);//
+ //printf("About to create texture\n");
ITexture* tex = driver->addTexture(name,im);
if(!tex){
lua_pushstring(L,"Failed to create texture!");
lua_error(L);
}
+ lua_newtable(L);
+ lua_pushlightuserdata(L,tex);
+ lua_setfield(L,-2,"texture");
+
+ return 1;
+}
+
+//newtexturefromfile(string file_name) -> {texture}
+int newitexturefromfile(lua_State* L){
+ const char* strpath = lua_tostring(L,-1);
+ lua_pop(L,1);
+ ITexture* tex = driver->getTexture(strpath);
+ if(!tex){
+ lua_pushstring(L,"Failed to create texture!");
+ lua_error(L);
+ }
+
+ lua_newtable(L);
lua_pushlightuserdata(L,tex);
+ lua_setfield(L,-2,"texture");
return 1;
}
@@ -35,7 +57,10 @@ int newitexture(lua_State* L){
void itexture_register(lua_State* L){
- lua_getglobal(L,"video");
- lua_pushcfunction(L,newitexture);
- lua_setfield(L,-2,"newtexture");
+ lua_getglobal(L,"video");//{}
+ lua_pushcfunction(L,newitexture);//{},newitexture
+ lua_setfield(L,-2,"newtexture");//{}
+ lua_pushcfunction(L,newitexturefromfile);
+ lua_setfield(L,-2,"newtexturefromfile");
+ lua_pop(L,1);
}