CapsAdmin

Untitled

Jul 29th, 2011
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. if not HEADER then http.Get("http://oohh.googlecode.com/svn/trunk/source/oohh/game_sdk/CryEngine/CryAction/IEffectSystem.h", "", function(str)  HEADER = str end) end
  2.  
  3. local trans =
  4. {
  5.     ["CWeapon"] = "ToEntity<CWeapon>",
  6.    
  7.     ["bool"] = "ToBool",
  8.     ["const char*"] = "ToString",
  9.    
  10.     ["float"] = "ToNumber<float>",
  11.     ["int"] = "ToNumber<int>",
  12. }
  13.  
  14. function translate(type)
  15.     return trans[type] or (type:find("*", nil, true) and ("ToEntity<" .. type:gsub("*","") .. ">"))
  16. end
  17.  
  18. function DefineToBind(type, content)
  19.        
  20.     local defines = {}
  21.    
  22.     for key, value in pairs(content:Split(";")) do
  23.         if #value > 5 and value:find("%a+%(.+%)") and not value:find("{", nil, true) and not value:find("//", nil, true) then
  24.             table.insert(defines, value:Trim())
  25.         end
  26.     end
  27.        
  28.     local funcs = {}
  29.    
  30.     for key, line in pairs(defines) do
  31.         local retrn, func, args = line:match("virtual%s*([%a_]-*?)%s+(.-)%((.+)%)")
  32.         if retrn and func and args then
  33.             args = args:Split(",")
  34.             for k,v in pairs(args) do
  35.                 args[k] = v:match("(.-)%a+$"):Trim():gsub("%s?%*%s?", "*")
  36.             end
  37.            
  38.             funcs[func] = {retrn = retrn, args = args}
  39.         end
  40.     end
  41.    
  42.     local cpp = ""
  43.    
  44.     for func, data in pairs(funcs) do
  45.         local str = ""
  46.        
  47.         str = str .. "LUAMTA_FUNCTION(" .. type .. ", " .. func .. ")\n"
  48.         str = str .. "{\n"
  49.         str = str .. "\toh->"
  50.        
  51.         if data.retrn == "void" then
  52.             local trans = translate(type)
  53.             if not trans then continue end
  54.             str = str .. trans .. "(1)("
  55.         else
  56.             local trans = translate(type)
  57.             if not trans then continue end
  58.             str = str .. "Push(" .. "oh->" .. trans .. "(1)("
  59.         end
  60.        
  61.         local failed = false
  62.        
  63.         for index, arg_type in pairs(data.args) do
  64.             index = index + 1
  65.            
  66.             local trans = translate(arg_type)
  67.             if not trans then failed = true break end
  68.             str = str .. "oh->" .. trans .. "(" .. index .. ")"
  69.            
  70.             if index-1 ~= #data.args then
  71.                 str = str .. ", "
  72.             end
  73.         end
  74.        
  75.         if failed then continue end
  76.        
  77.         str = str .. ");\n\n"
  78.        
  79.         if data.retrn == "void" then
  80.             str = str .. "\treturn 0;\n"
  81.         else
  82.             str = str .. "\treturn 1;\n"
  83.         end
  84.        
  85.         str = str .. "}\n\n"
  86.        
  87.         cpp = cpp .. str
  88.     end
  89.  
  90.     PrintTable(defines)
  91.     print(cpp)
  92. end
  93.  
  94. DefineToBind("CWeapon", HEADER)
  95.  
  96. --[[
  97. {
  98.     [1] = "virtual bool Update(float delta) = 0",
  99.     [2] = "virtual bool Deactivating(float delta) = 0",
  100.     [3] = "virtual void GetMemoryStatistics(ICrySizer * s) = 0",
  101.     [4] = "virtual void SetFlags(int flags) = 0",
  102.     [5] = "virtual bool SetParticleEffect(const char* name) = 0",
  103.     [6] = "virtual void Update(float delta) = 0",
  104.     [7] = "virtual void GetMemoryStatistics(ICrySizer * s) = 0",
  105.     [8] = "virtual EffectId GetEffectId(const char* name) = 0",
  106.     [9] = "virtual void Activate(const EffectId& eid) = 0",
  107.     [10] = "virtual bool BindEffect(const char* name, IEffect* pEffect) = 0",
  108.     [11] = "virtual IGroundEffect* CreateGroundEffect(IEntity* pEntity) = 0",
  109.     [12] = "DECLARE_GAMEOBJECT_FACTORY(IEffect)",
  110. }LUAMTA_FUNCTION(CWeapon, SetParticleEffect)
  111. {
  112.     oh->Push(oh->ToEntity<CWeapon>(1)(oh->ToString(2));
  113.  
  114.     return 1;
  115. }
  116.  
  117. LUAMTA_FUNCTION(CWeapon, Update)
  118. {
  119.     oh->ToEntity<CWeapon>(1)(oh->ToNumber<float>(2));
  120.  
  121.     return 0;
  122. }
  123.  
  124. LUAMTA_FUNCTION(CWeapon, CreateGroundEffect)
  125. {
  126.     oh->Push(oh->ToEntity<CWeapon>(1)(oh->ToEntity<IEntity>(2));
  127.  
  128.     return 1;
  129. }
  130.  
  131. LUAMTA_FUNCTION(CWeapon, BindEffect)
  132. {
  133.     oh->Push(oh->ToEntity<CWeapon>(1)(oh->ToString(2), oh->ToEntity<IEffect>(3));
  134.  
  135.     return 1;
  136. }
  137.  
  138. LUAMTA_FUNCTION(CWeapon, GetEffectId)
  139. {
  140.     oh->Push(oh->ToEntity<CWeapon>(1)(oh->ToString(2));
  141.  
  142.     return 1;
  143. }
  144.  
  145. LUAMTA_FUNCTION(CWeapon, SetFlags)
  146. {
  147.     oh->ToEntity<CWeapon>(1)(oh->ToNumber<int>(2));
  148.  
  149.     return 0;
  150. }
  151.  
  152. LUAMTA_FUNCTION(CWeapon, Deactivating)
  153. {
  154.     oh->Push(oh->ToEntity<CWeapon>(1)(oh->ToNumber<float>(2));
  155.  
  156.     return 1;
  157. }
  158.  
  159. LUAMTA_FUNCTION(CWeapon, GetMemoryStatistics)
  160. {
  161.     oh->ToEntity<CWeapon>(1)(oh->ToEntity<ICrySizer>(2));
  162.  
  163.     return 0;
  164. }
  165.  
  166.  
  167. ]]
Advertisement
Add Comment
Please, Sign In to add comment