C# function call to LUA variable.  x = CsharpCalled(); print(x); menu

User Tag List

Results 1 to 5 of 5
  1. #1
    jarjar1's Avatar Sergeant
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    52
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    C# function call to LUA variable. x = CsharpCalled(); print(x);

    How can I get the return value in my lua script from calling my C# function.

    Ex:

    Code:
    C#
            public static string GetFreeSlots(IntPtr pLuaState)
            {
               // List<string> FreeSlots = WoWScript.Execute("return GetContainerNumFreeSlots(0)");   //returns 15 as string (correct)
              //  List<string> FreeSlots = WoWScript.Execute("wfaInput(GetContainerNumFreeSlots(0))"); //(returns 15 also correct)
                  WoWScript.Execute("wfaInput(GetContainerNumFreeSlots(0))"); //(returns 15 also correct)
                return "5";
            }
    ingame I type: /script x = FreeSlots(); print(x);

    and I always get nil.

    I tried 2 ways of calling ExecuteBuffer and getting the return value. the cleanCore popping off stack vars way and the other way making a second input function. I think I missed something simple yet important.

    C# function call to LUA variable.  x = CsharpCalled(); print(x);
  2. #2
    frostzorn's Avatar Banned
    Reputation
    2
    Join Date
    Dec 2011
    Posts
    6
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Push return value. Return number of arguments pushed.

    Code:
    int __cdecl Script_GetSelectedItem( lua_State *L )
    {
    	if( !LuaListBox::IsValid( L, 1 ) )
    		return luaL_error( L, "Usage: ListBox:GetSelectedItem();" );
    
    	try
    	{
    		CListBox *pListBox = LuaListBox::Get( L, 1 );
    		CListBoxEntry *pItem = pListBox->GetSelectedItem();
    		LuaListBoxEntry::Push( L, pItem );
    		return 1;
    	}
    	catch( ... ) { }
    	return 0;
    }

  3. #3
    jarjar1's Avatar Sergeant
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    52
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have tested and made sure the stack has 2 values on it, the 2 return values from GetNumbBagSlots..(). Still no dice. I tried using lua_pushnum, lua_pushstring, lua_pushvalue. It does not matter, always returns nil. Also tried calling it from frame in endscene. Maybe there is a certain function you need to call or something like GetLocalizedText passing your variable?

    But that makes it much more cumbersome to write bot scripts.

    privatepaste.com :: Paste ID 2120102aa6

    Originally Posted by frostzorn View Post
    Push return value. Return number of arguments pushed.
    Code:
    int __cdecl Script_GetSelectedItem( lua_State *L )
    {
    	if( !LuaListBox::IsValid( L, 1 ) )
    		return luaL_error( L, "Usage: ListBox:GetSelectedItem();" );
    
    	try
    	{
    		CListBox *pListBox = LuaListBox::Get( L, 1 );
    		CListBoxEntry *pItem = pListBox->GetSelectedItem();
    		LuaListBoxEntry::Push( L, pItem );
    		return 1;
    	}
    	catch( ... ) { }
    	return 0;
    }

  4. #4
    jarjar1's Avatar Sergeant
    Reputation
    1
    Join Date
    Oct 2012
    Posts
    52
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I little more explanation could of been helpful :P. Didn't understand what you meant until took a look at the script functions.

    Originally Posted by frostzorn View Post
    Push return value. Return number of arguments pushed.

    Code:
    int __cdecl Script_GetSelectedItem( lua_State *L )
    {
    	if( !LuaListBox::IsValid( L, 1 ) )
    		return luaL_error( L, "Usage: ListBox:GetSelectedItem();" );
    
    	try
    	{
    		CListBox *pListBox = LuaListBox::Get( L, 1 );
    		CListBoxEntry *pItem = pListBox->GetSelectedItem();
    		LuaListBoxEntry::Push( L, pItem );
    		return 1;
    	}
    	catch( ... ) { }
    	return 0;
    }

  5. #5
    FinnX's Avatar Banned
    Reputation
    40
    Join Date
    Aug 2009
    Posts
    82
    Thanks G/R
    0/0
    Trade Feedback
    1 (100%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
            public static string GetLocalizedText(string Local)
            {
                try
                {
                    String Command = Local;
    
                    uint Lua_GetLocalizedText_Space = Memory.Manager.WoW.AllocateMemory(Encoding.UTF8.GetBytes(Command).Length + 1);
    
                    uint ClntObjMgrGetActivePlayerObj = (uint)Memory.Manager.WoW.MainModule.BaseAddress + (uint)Enums.EndScene.ClntObjMgrGetActivePlayerObj;
                    uint FrameScript__GetLocalizedText = (uint)Memory.Manager.WoW.MainModule.BaseAddress + (uint)Enums.EndScene.FrameScript__GetLocalizedText;
    
                    Memory.Manager.WoW.WriteBytes(Lua_GetLocalizedText_Space, Encoding.UTF8.GetBytes(Command));
    
                    String[] asm = new String[] 
                        {
                            "call " + (uint)ClntObjMgrGetActivePlayerObj,
                            "mov ecx, eax",
                            "push -1",
                            "mov edx, " + Lua_GetLocalizedText_Space + "",
                            "push edx",
                            "call " + (uint)FrameScript__GetLocalizedText,
                            "retn",
                        };
    
                    string Result = Encoding.UTF8.GetString(EndScene.InjectAndExecute(asm));
    
                    Memory.Manager.WoW.FreeMemory(Lua_GetLocalizedText_Space);
                    return Result;
                }
                catch { return String.Empty; }
            }

Similar Threads

  1. Replies: 11
    Last Post: 11-21-2011, 12:25 AM
  2. [Help] Lua Variable question
    By Swarfega in forum WoW EMU Questions & Requests
    Replies: 0
    Last Post: 03-21-2009, 03:19 PM
  3. LUA Variable Help (NOT A BIG SCRIPT)
    By Envoke in forum WoW EMU Questions & Requests
    Replies: 5
    Last Post: 03-19-2009, 08:14 PM
  4. ASM function call?
    By akh in forum WoW Memory Editing
    Replies: 15
    Last Post: 09-02-2008, 12:31 AM
All times are GMT -5. The time now is 12:39 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