Call lua function and get result menu

User Tag List

Results 1 to 5 of 5
  1. #1
    starfish99's Avatar Corporal
    Reputation
    31
    Join Date
    May 2008
    Posts
    24
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Call lua function and get result

    I'd like to share my experiments about calling lua functions and getting their results in outer program.

    Most lua functions we can see in IDA, only have one argument, which is always called "lua state". Then how such fuctions get their true aruguments and how they return their results(maybe several returned values)?

    these are lua stack addresses and functions to get arguments and set values:

    //lua state address
    ptrLua_L = $012E87EC;

    //get arguments from lua stack
    ptrLua_ToString = $007AD920;
    ptrLua_ToNumber = $007AD870;

    //push results to lua stack
    ptrLua_PushString = $007ADB90;
    ptrLua_PushNumber = $007ADAE0;
    ptrLua_PushNil = $007ADAC0;

    //this address shows which addon is call lua function, the value is addon's name(string)
    ptrAddon = $012EA330;

    now, I give an example for calling the lua function : GetPlayerMapPosition(unit)
    this func needs a string arg and returns two number values,like this:
    x,y = GetPlayerMapPosition("player")

    ptrGetPlayerMapPosition = $004BBD70


    type

    TLua_ToString = function(Lua_L,index,Zero:LongWord):PChar;cdecl;
    TLua_ToNumber = function(Lua_L,index : LongWord):double;cdecl;

    TLua_PushString = function(Lua_L:Longword;value:PChar):Integer;cdecl;
    TLua_PushNumber = function(Lua_L:LongWord;valueouble):Integer;cdecl;
    TLua_PushNil = function(Lua_L:LongWord):Integer;cdecl;

    var

    Lua_ToString : TLua_ToString = Pointer(ptrLua_ToString);
    Lua_ToNumber : TLua_ToNumber = Pointer(ptrLua_ToNumber);
    Lua_PushString : TLua_PushString = Pointer(ptrLua_PushString);
    Lua_PushNumber : TLua_PushNumber = Pointer(ptrLua_PushNumber);
    Lua_PushNil : TLua_PushNil = Pointer(ptrLua_PushNil);

    then,it's easy to call a lua function

    procedure MyGetPlayerMapPosition(var x,y : double)
    var
    unit : PChar;
    Lua_L : DWord;

    begin

    //prepare parameters

    unit := 'player';
    Lua_L := GetDWordValue(ptrLua_L);

    //push argument to lua stack

    Lua_PushString(Lua_L,unit);

    //cal lua function

    asm
    mov ebx,ptrGetPlayerMapPosition
    call ebx
    end;

    //get returned values from lua stack

    x := Lua_ToNumber(Lua_L,1);
    y := Lua_ToNumber(Lua_L,2);

    end;


    If the lua function we are calling is protected, we should clear addon value.
    example code is :

    ...
    mov [ptrAddon],0
    mov ebx,ptrGetPlayerMapPosition
    call ebx
    ...

    That's all.

    Call lua function and get result
  2. #2
    Nesox's Avatar ★ Elder ★
    Reputation
    1280
    Join Date
    Mar 2007
    Posts
    1,238
    Thanks G/R
    0/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice you sir deserves a rep cookie! +Rep
    Last edited by Nesox; 12-26-2008 at 06:57 AM.

  3. #3
    luciferc's Avatar Contributor
    Reputation
    90
    Join Date
    Jul 2008
    Posts
    373
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice. +Rape

  4. #4
    charly's Avatar Established Member
    Reputation
    63
    Join Date
    Jan 2007
    Posts
    72
    Thanks G/R
    15/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx for sharing. +rep


  5. #5
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nicely done.

    Just wanted to point out you can avoid manually manging the stack if you use RunScript to pass args etc.

Similar Threads

  1. Game crashes when calling lua function before loading screen
    By avizer in forum WoW Memory Editing
    Replies: 6
    Last Post: 04-03-2013, 09:04 PM
  2. Calling lua functions requiering an hardware event
    By Frosttall in forum WoW Memory Editing
    Replies: 10
    Last Post: 12-22-2012, 11:19 AM
  3. How to execute LUA function and get it's result?
    By piiters in forum WoW Bots Questions & Requests
    Replies: 2
    Last Post: 06-07-2010, 05:51 AM
  4. Calling Lua Functions from DLL
    By Viano in forum WoW Memory Editing
    Replies: 19
    Last Post: 07-28-2009, 07:56 PM
  5. Calling LUA Functions
    By cloud_wizard in forum WoW Memory Editing
    Replies: 7
    Last Post: 01-04-2009, 08:24 AM
All times are GMT -5. The time now is 07:47 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search