Jump to content

Converting Lua to c++


Guest marx123

Recommended Posts

oke so my question is is it possible to convert lua scripts to c++ for mangos example like we all know mangos is more complicated then arc or whatever else so mabye someone wanna join me and lets starting converting lua custom scripts to c++ (for mangos) that mangos users can have some fun.. im not that good in c++ but mabye anyone is intrested helping out

Link to comment
Share on other sites

you could write a metacompiler that converts lua to C++

Though I think this would probably be more difficult than just converting the scripts themselves.

The languages are also very different. And given the quality of most of these Lua scripts, I would really hate to see what they look like in C++. I took a badly written 591 line Lua script and converted it 102 lines of reasonable C++, an automatic generator would have probably given around 500-600 lines of equally redundant code.

If you must run bad Lua scripts, than a Lua engine is probably easier. Otherwise, just redo what you need and get away from Lua altogether.

Link to comment
Share on other sites

ofc im learning myself reading some books and some guides from net but im not that pro yet...

http://pastebin.com/TsH25AWv

http://pastebin.com/8vDdHPmZ

Instead, the second script you can use this.

/* ScriptData
SDName: item_levelplayer
SD%Complete: 100
SDComment: Used for Leveling characters Random
SDCategory: Items
EndScriptData */

#include"precompiled.h"

bool ItemUse_item_levelplayer(Player* pPlayer, Item* pItem, const SpellCastTargets &pTargets)
{
if ((pPlayer->isInCombat()) || (pPlayer->isInFlight()) || (pPlayer->isDead()))
{
     pPlayer->SendEquipError(EQUIP_ERR_NOT_IN_COMBAT, pItem, NULL);
       return false;
}
     pPlayer->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);

   outstring_log("player level %i",pPlayer->getLevel());
   if(((pPlayer->getLevel()) + 5) > 80)
   {
       outstring_log("playerlevel+5 > 80 (%i+5=%i)",pPlayer->getLevel(),pPlayer->getLevel()+5);
       if((80 - (pPlayer->getLevel())) > 0)
       {
           outstring_log("leveling for %i levels",(80-(pPlayer->getLevel())));
           pPlayer->GiveLevel(pPlayer->getLevel()+(80 - (pPlayer->getLevel())));  
       }
       else
       {
           outstring_log("level would be 81+, exiting function");
           return true;
       }
   }
   else
   {
       outstring_log("leveling for 5 levels");
       pPlayer->GiveLevel(pPlayer->getLevel()+5);
   }
   pPlayer->DestroyItemCount(pItem->GetEntry(),1,true);
   return true;
}
void AddSC_item_levelplayer()
{
   Script *newscript;

     newscript = new Script;
   newscript->Name="item_levelplayer";
   newscript->pItemUse = &ItemUse_item_levelplayer;
   newscript->RegisterSelf();
   outstring_log("SD2: item_levelplayer loaded");
}

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use