CapsAdmin

Untitled

Mar 29th, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.92 KB | None | 0 0
  1. #include "StdAfx.h"
  2.  
  3. #include "entity.hpp"
  4.  
  5. #include "lua\init.hpp"
  6. #include "lua\sugar\object_reg.hpp"
  7.  
  8. object(IEntity, entity)
  9.  
  10.     function(GetClass)
  11.         lua_pushstring(L, self->GetClass()->GetName());
  12.     end
  13.  
  14.     function(Remove)
  15.         gEnv->pEntitySystem->RemoveEntity(self->GetId(), true);
  16.         lua_pushnil(L);
  17.     end
  18.  
  19.     function(SetSize)
  20.         self->SetScale(Vec3(1,1,1) * lua_tonumber(L, 2));
  21.     ends
  22.     // ends will return self again. this means you can do
  23.     // fancy shit like local ent = CreateEntity("myent"):SetPos(Vec3(0,0,100)):SetAngles(Ang3(90,0,0))
  24.  
  25.     function(__tostring)
  26.         lua_pushfstring(L, "%s[%d][%s]", PRINTNAME, self->GetId(), self->GetClass()->GetName());
  27.     end
  28.  
  29.     function(__len)
  30.         lua_pushnumber(L, self->GetId());
  31.     end
  32.  
  33.     function(__index1) // __index1 is called if __index doesn't return anything
  34.         string key = lua_tostring(L, 2);
  35.  
  36.         if (key == "id")
  37.         {
  38.             __len(L);
  39.  
  40.             return 1;
  41.         }
  42.         else if (key == "omg")
  43.         {
  44.             lua_pushstring(L, "HHPOOøPYLSHIT");
  45.  
  46.             return 1;
  47.         }
  48.         __luaindex() // this will try to call __luaindex which entities can override
  49.     end
  50.  
  51.     // R will register the given function like so _R.IEntity.MyFunc where MyFunc is the argument
  52.     // RR will do the same as R but the second argument can be an alias of your function
  53.  
  54.     declare{
  55.         REG(SetSize)
  56.         REG(Remove)
  57.  
  58.         ALIAS(Remove, Destroy) //  Destroy will become an alias of Remove
  59.         ALIAS(Remove, Delete)
  60.  
  61.         REG(__index)
  62.         REG(__newindex)
  63.         REG(__eq)
  64.  
  65.         REG(__tostring)
  66.         REG(__len)
  67.         REG(__index1)
  68.     }}
Advertisement
Add Comment
Please, Sign In to add comment