CapsAdmin

Untitled

Jul 29th, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.02 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)->" .. func .. "("
  55.         else
  56.             local trans = translate(type)
  57.             if not trans then continue end
  58.             str = str .. "Push(" .. "oh->" .. trans .. "(1)->" .. func .. "("
  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.        
  78.         if data.retrn == "void" then
  79.             str = str .. ");\n\n"
  80.             str = str .. "\treturn 0;\n"
  81.         else
  82.             str = str .. "));\n\n"
  83.             str = str .. "\treturn 1;\n"
  84.         end
  85.        
  86.         str = str .. "}\n\n"
  87.        
  88.         cpp = cpp .. str
  89.     end
  90.  
  91.     PrintTable(defines)
  92.     print(cpp)
  93. end
  94.  
  95. DefineToBind("CWeapon", HEADER)
  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.  
  111. LUAMTA_FUNCTION(CWeapon, SetParticleEffect)
  112. {
  113.     oh->Push(oh->ToEntity<CWeapon>(1)->SetParticleEffect(oh->ToString(2)));
  114.  
  115.     return 1;
  116. }
  117.  
  118. LUAMTA_FUNCTION(CWeapon, Update)
  119. {
  120.     oh->ToEntity<CWeapon>(1)->Update(oh->ToNumber<float>(2));
  121.  
  122.     return 0;
  123. }
  124.  
  125. LUAMTA_FUNCTION(CWeapon, CreateGroundEffect)
  126. {
  127.     oh->Push(oh->ToEntity<CWeapon>(1)->CreateGroundEffect(oh->ToEntity<IEntity>(2)));
  128.  
  129.     return 1;
  130. }
  131.  
  132. LUAMTA_FUNCTION(CWeapon, BindEffect)
  133. {
  134.     oh->Push(oh->ToEntity<CWeapon>(1)->BindEffect(oh->ToString(2), oh->ToEntity<IEffect>(3)));
  135.  
  136.     return 1;
  137. }
  138.  
  139. LUAMTA_FUNCTION(CWeapon, GetEffectId)
  140. {
  141.     oh->Push(oh->ToEntity<CWeapon>(1)->GetEffectId(oh->ToString(2)));
  142.  
  143.     return 1;
  144. }
  145.  
  146. LUAMTA_FUNCTION(CWeapon, SetFlags)
  147. {
  148.     oh->ToEntity<CWeapon>(1)->SetFlags(oh->ToNumber<int>(2));
  149.  
  150.     return 0;
  151. }
  152.  
  153. LUAMTA_FUNCTION(CWeapon, Deactivating)
  154. {
  155.     oh->Push(oh->ToEntity<CWeapon>(1)->Deactivating(oh->ToNumber<float>(2)));
  156.  
  157.     return 1;
  158. }
  159.  
  160. LUAMTA_FUNCTION(CWeapon, GetMemoryStatistics)
  161. {
  162.     oh->ToEntity<CWeapon>(1)->GetMemoryStatistics(oh->ToEntity<ICrySizer>(2));
  163.  
  164.     return 0;
  165. }
  166.  
  167.  
  168.  
  169. ]]
Advertisement
Add Comment
Please, Sign In to add comment