lugre_random_L.cpp

Go to the documentation of this file.
00001 #include "lugre_prefix.h"
00002 #include "lugre_luabind.h"
00003 #include "lugre_random.h"
00004 #include <Ogre.h>
00005 
00006 extern "C" {
00007     #include "lua.h"
00008     #include "lauxlib.h"
00009     #include "lualib.h"
00010 }
00011 
00012 using namespace Ogre;
00013 
00014 class lua_State;
00015     
00016 namespace Lugre {
00017 
00018 class cRandom_L : public cLuaBind<cRandom> { public:
00020         virtual void RegisterMethods    (lua_State *L) { PROFILE
00021             #define REGISTER_METHOD(methodname) mlMethod.push_back(make_luaL_reg(#methodname,&cRandom_L::methodname));
00022             REGISTER_METHOD(GetInt);
00023             REGISTER_METHOD(GetFloat);
00024             REGISTER_METHOD(Destroy);
00025             
00026             lua_register(L,"CreateRandom",  &cRandom_L::CreateRandom);
00027         }
00028 
00029     // object methods exported to lua
00030 
00031         // todo : rotation, position, aspect ratio, near/farclip...
00032             
00034         static int      Destroy             (lua_State *L) { PROFILE delete checkudata_alive(L); return 0; }
00035         
00038         static int      GetInt              (lua_State *L) { PROFILE 
00039             int argc = lua_gettop(L) - 1; // arguments, not counting "this"-object
00040             if(argc == 1){
00041                 lua_pushnumber(L,
00042                     checkudata_alive(L)->GetInt(luaL_checkint(L,2))
00043                 );
00044             } else {
00045                 lua_pushnumber(L,
00046                     checkudata_alive(L)->GetInt(
00047                         luaL_checkint(L,2),
00048                         luaL_checkint(L,3)
00049                     )
00050                 );
00051             }
00052             return 1;
00053         }
00054 
00056         static int      GetFloat                (lua_State *L) { PROFILE 
00057             lua_pushnumber(L,
00058                 checkudata_alive(L)->GetFloat()
00059             );
00060             return 1;
00061         }
00062 
00063     // static methods exported to lua
00064 
00066         static int      CreateRandom    (lua_State *L) { PROFILE
00067             cRandom* target = new cRandom(luaL_checkint(L,1));
00068             return CreateUData(L,target);
00069         }
00070         
00071         virtual const char* GetLuaTypeName () { return "lugre.Random"; }
00072 };
00073 
00075 void    cRandom::LuaRegister    (lua_State *L) { PROFILE
00076     cLuaBind<cRandom>::GetSingletonPtr(new cRandom_L())->LuaRegister(L);
00077 }
00078 
00079 };

Generated on Wed May 23 06:00:15 2012 for cpp by  doxygen 1.5.6