From 06d3e8182d018ca613f177f6ff7a3bbb6494cc79 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 28 May 2018 17:07:04 -0400 Subject: Various additions Various additions, updates, and bugfixes while making mahjong solitare. --- src/client/lua_api/video/itexture.cpp | 37 +++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'src/client/lua_api/video/itexture.cpp') diff --git a/src/client/lua_api/video/itexture.cpp b/src/client/lua_api/video/itexture.cpp index a7f4652..599a448 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); } -- cgit v1.2.3-70-g09d2