diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2018-05-28 17:07:04 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2018-05-28 17:07:04 -0400 |
| commit | 06d3e8182d018ca613f177f6ff7a3bbb6494cc79 (patch) | |
| tree | 18289e9d48c03cb3910e5fbe27ffd18c6b81eb53 /src/client/lua_api/video/itexture.cpp | |
| parent | 5fc253ce728c6e078886e092376c2e0f0320ebd9 (diff) | |
| download | brokengine-06d3e8182d018ca613f177f6ff7a3bbb6494cc79.tar.gz brokengine-06d3e8182d018ca613f177f6ff7a3bbb6494cc79.tar.bz2 brokengine-06d3e8182d018ca613f177f6ff7a3bbb6494cc79.zip | |
Various additions
Various additions, updates, and bugfixes while making mahjong solitare.
Diffstat (limited to 'src/client/lua_api/video/itexture.cpp')
| -rw-r--r-- | src/client/lua_api/video/itexture.cpp | 37 |
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..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); } |
