Any C++ Pro's?

DY357LXDY357LX Playing since day 1. Still can't Comm.England Join Date: 2002-10-27 Member: 1651Members, Constellation
<div class="IPBDescription">I R Nub. (Reading LUA value from C++)</div>Let's say I want to access a LUA function/variable/value/whatever from a C++ program, is it possible and if so, how?

To be completely exact, I want to see if I can read the GetHonorCurrency() (LUA) value from World of Warcraft. (Info on the function is here: <a href="http://www.wowwiki.com/API_GetHonorCurrency" target="_blank">http://www.wowwiki.com/API_GetHonorCurrency</a> )

Obviously it's coded in LUA so I need a way to access GetHonorCurrency and the value it holds from C++.

(For the non-WoW players, this is an open/public function, it's not cheating or dodgy in anyway. WoW's 3rd party AddOns can access this function for whatever reason but obviously not alter it because it's serverside.)

Any ideas? (Without messing with ReadProcessMemory because Blizzard will probably ban me for that.)

Comments

  • douchebagatrondouchebagatron Custom member title Join Date: 2003-12-20 Member: 24581Members, Constellation, Reinforced - Shadow
    i'm decent at c++ but i've never touched lua, perhaps <a href="http://www.codeproject.com/KB/cpp/luaincpp.aspx" target="_blank">this</a> will be helpful.
  • TalesinTalesin Our own little well of hate Join Date: 2002-11-08 Member: 7710NS1 Playtester, Forum Moderators
    Have never used LUA, but am a C/C++ coder from back in the day. Also means I have an instinctual dislike of anything '-script' aside maybe from batch or bash.
    May be an API sitting around to allow what you want, but I have no idea. Way I'd approach it would be to alter a text or binary file (assuming LUA can write out to disk) and have a standalone compiled program watching that file and sleeping for a set period, reading it in or just checking the alteration/touch date and time if it's a large dataset you want to play with.

    More than a bit of a kludge, with its own limitations (high cpu usage with low sleep, high hdd access, possibility of a race condition where LUA will try to write to the file while the C prog has it open and locked, inability to move data BACK from the C prog without the LUA watching for another set of changes... potentially worked mostly around with the use of a second flag/lockfile to indicate new activity) but it'd allow you to get a bit of data from a running LUA script to a running compiled C executable.

    If it's a single function you want to execute when a given condition is correct in the LUA, and if you have the ability to call/run external programs within that script, could always just call the program with whatever value as a command line option, and have it return the result of whatever calculation you wanted to perform outside of LUA.


    Really depends on what you actually want to DO with it.
  • [WHO]Them[WHO]Them You can call me Dave Join Date: 2002-12-11 Member: 10593Members, Constellation
    Pretty much what Talesin said. There's no generic way to get at LUA data from C++. WoW would have to provide you with an existing API to get at it's LUA virtual machine.

    I'm not familiar with WoW modding. But if they support intermixing of C++ and LUA addons (and a C++ addon is what you're writing), but not the direct access you need. Then you'll need to smuggle the data, but hopefully with something less severe than file i/o. Look for any place that you can write to a buffer in LUA and read from that same buffer in C++, possibly abusing the chat logs?

    If they don't support C++ addons at all, you're pretty much hosed without reading process memory or abusing debug logs that get written to disk.
  • spellman23spellman23 NS1 Theorycraft Expert Join Date: 2007-05-17 Member: 60920Members
    A weird (but viable) round-about would be to have separate scripts that call each other. i.e. Have a c++ script call a LUA script to dump the value into a file which the C++ program then greps the value from. I did this all the time to mix and match different Python, Perl, tcl scripts together into a giant unit.
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    Thanks for the replies. I'll investigate your ideas when I get home tonight.

    Thanks again.
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    UPDATE: Here's a small update regarding what I'm trying to achieve with this C++ + LUA stuff.

    I'm basically trying to get access to certain NS2 variables/values so I can display them on the LCD of my G15 keyboard.
    (Playername, mapname, server ip, max players, current weapon that sort of thing.)

    Seeing as I can't (yet - more reading to be done) call/read the NS2 LUA functions/values from C++, I wanted to have NS2 spit out this info to a text file and then have a C++ .exe that reads the text file and passes it to the keyboard LCD.


    <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=110808&st=0&gopid=1792103&#entry1792103" target="_blank">More here</a>.


    You may have heard Flayra mention in the Podcast17 interview, that he too has a G15 but has no immediate plans to support it.
    (Completely understandable, he's busy with NS2 etc.)

    So I'm seeing if I can manage any of it... it's not going well. :-)
  • douchebagatrondouchebagatron Custom member title Join Date: 2003-12-20 Member: 24581Members, Constellation, Reinforced - Shadow
    edited August 2010
    Is it not possible to use a named pipe? I would think Lua would support something like that.

    edit: here is some info on a lua library that provides this functionality: <a href="http://w3.impa.br/~diego/software/luasocket/old/luasocket-2.0-alpha/" target="_blank">click</a>
  • DY357LXDY357LX Playing since day 1. Still can&#39;t Comm. England Join Date: 2002-10-27 Member: 1651Members, Constellation
    @6john Thank you. Am not 100% sure how to use something like this but will give it a looksee.
Sign In or Register to comment.