Announcement

Collapse
No announcement yet.

Lua Lanes with MemoryEx

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lua Lanes with MemoryEx

    webultra posted a method of using Lua Lanes with the AMS functions and it does this by passing _G to the lane so the lane, should, have everything on the stack but if you create some functions that use MemoryEx then the functions fail within the lane, other plugins such as Wow64 and ListBoxEx and ListIcon work just fine with passing _G but some objects such as the Paragraph fail but they don't fail as in a crash like MemoryEx they just don't do anything.

    Putting the function locally within the lane like so

    Code:
    [COLOR="#0000FF"]local[/COLOR] SetText [COLOR="#FF0000"]=[/COLOR] [COLOR="#0000FF"]function[/COLOR](Txt)
      [COLOR="#0000FF"]local[/COLOR] t [COLOR="#FF0000"]=[/COLOR] MemoryEx[COLOR="#FF0000"].[/COLOR]Allocate(String[COLOR="#FF0000"].[/COLOR]Length(Txt) + [COLOR="#000000"]1[/COLOR])
      MemoryEx[COLOR="#FF0000"].[/COLOR]String(t[COLOR="#FF0000"],[/COLOR] -[COLOR="#000000"]1[/COLOR][COLOR="#FF0000"],[/COLOR] MEMEX_ASCII[COLOR="#FF0000"],[/COLOR] Txt)
      [COLOR="#0000FF"]local[/COLOR] y [COLOR="#FF0000"]=[/COLOR] Bitwise[COLOR="#FF0000"].[/COLOR]Or(Bitwise[COLOR="#FF0000"].[/COLOR]ASL([COLOR="#000000"]0[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]16[/COLOR])[COLOR="#FF0000"],[/COLOR][COLOR="#000000"]0[/COLOR])
      [COLOR="#0000FF"]local[/COLOR] x [COLOR="#FF0000"]=[/COLOR] Bitwise[COLOR="#FF0000"].[/COLOR]Or(Bitwise[COLOR="#FF0000"].[/COLOR]ASL([COLOR="#000000"]0[/COLOR][COLOR="#FF0000"],[/COLOR][COLOR="#000000"]16[/COLOR])[COLOR="#FF0000"],[/COLOR]y)
      [COLOR="#0000FF"]if[/COLOR] User32[COLOR="#FF0000"].[/COLOR]SendMessageA(StatusBar[COLOR="#FF0000"].[/COLOR]Handle[COLOR="#FF0000"],[/COLOR]0x401[COLOR="#FF0000"],[/COLOR]x[COLOR="#FF0000"],[/COLOR]t) [COLOR="#FF0000"]==[/COLOR] [COLOR="#000000"]0[/COLOR] [COLOR="#0000FF"]then[/COLOR]
       MemoryEx[COLOR="#FF0000"].[/COLOR]Free(t)
       [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]false[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"Can't set text"[/COLOR]
      [COLOR="#0000FF"]else[/COLOR]
       MemoryEx[COLOR="#FF0000"].[/COLOR]Free(t)
       [COLOR="#0000FF"]return[/COLOR] [COLOR="#0000FF"]true[/COLOR][COLOR="#FF0000"],[/COLOR] [COLOR="#800080"]"OK"[/COLOR]
      [COLOR="#0000FF"]end[/COLOR]
    [COLOR="#0000FF"]end[/COLOR];
    fails also and the error via pcall is:

    Code:
     [B][string "MXO"]:1097: attempt to call global 'type' (a nil value)[/B]
    1097 is not the lines the code is on and StatusBar.Handle is successfully passed to the lane via _G and the SetText function works without issue outside the lane so does anyone know how to pass MemoryEx over to the lanes?

  • #2
    MXO:1097 is line 1097 of the L-OOP module in MemoryEx, which apparently cannot find the function 'type' in _G when MemoryEx functions are called inside a lane.
    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler

    Comment


    • #3
      just to be sure , did you manually load the MemoryEx plugin from within the created lane

      wrap the Application.LoadActionPlugin(params) call in a pcall and check the result

      there are very few plugins that will function properly if only loaded onto the new state via _G

      Comment


      • #4
        I never you know, will give it a bash later on but I suppose I'll have to reload the LH Module also.

        Comment


        • #5
          Originally posted by Shrek View Post
          I never you know, will give it a bash later on but I suppose I'll have to reload the LH Module also.
          That's probably not necessary, first try without reloading the module but with reloading MemoryEx.
          Bas Groothedde
          Imagine Programming :: Blog

          AMS8 Plugins
          IMXLH Compiler

          Comment


          • #6
            Happy new year :yes

            I get the same

            Code:
            [B][string "MXO"]:1097: attempt to call global 'type' (a nil value)[/B]
            error with the "SetText" function when I Application.LoadActionPlugin the MemoryEx plugin in the Lane although Application.LoadActionPlugin reports as loaded from Application.GetLastError, pcall reports fine.

            Trying to load MemoryEx within the Lane then loading the LH file throws:

            Code:
             [B][string "MXO"]:1087: attempt to index global 'Library' (a nil value)[/B]

            Comment


            • #7
              Happy new year! It's my first 2014 post! WOHOOOO! lol.... Well, it's great to see that my examples are still running here

              Shrek,
              First, when a lane fails, it throws an error but you need to catch it (i did it in a timer by checking the lane status and getting the error msg with the :join function).

              Second, to pass successfully a message to a lane, I recommend you to use linda objects (:send and :receive functions). So, instead of trying to use MemoryEx functions from a lane, you could declare some global functions to receive an instruction to use the MemoryEx functions in the main state. I did an example about linda objects on Shadiku's forum but it does not exist anymore (maybe rex could have a copy).

              Third, did you tried to load the module with pure lua functions? Anyway, when a lane is created and you pass the _G variable to it, you are copying it. So, maybe the MemoryEx functions are trying to locate a global variable declared on the main state and not on the lane state (different memory addresses) and that's probably why it is failing. imagine programming knows better how does the MemoryEx work.

              Comment


              • #8
                cheers, you know I messed about with the linda before but I could never really get it working without crashing, I was trying to cancel a lane at the time though and that's not always achievable so I found out so I gave up on the linda but an example would be cool if rex does have one.

                Comment


                • #9
                  I use a mac air now :( so i can not test hehe, but let me plug in my hdd to search for it.

                  Comment


                  • #10
                    thanks :yes

                    Comment


                    • #11
                      from an old post of mine:

                      --[[Using Action plugins (Kudos and thanks to all plugin developers !) with 'Lua Lanes' test notes:]];

                      --[[Notes: if an action plugin is loaded within the AMS lua state before any lane functionality,
                      the plugin functionality is usually not properly passed on in the _G table for a lane.
                      you could try things with passing the _M (metatable) instead of _G to the lane,
                      there are probably more fancy under the bonnet of lua and lanes functionality,
                      however for simplicity the below tested method with Ams and Action plugins seems
                      to work without issues within a Lane.
                      ]];


                      --[[Also Note: Application.LoadActionPlugin("fullpath") does not work within a lane and some
                      action plugins (memory plugin being one) can cause 'Lanes' funtionality to crash, if loaded
                      in the main AMS lua state before calling any "Lanes" functionality so try this:

                      to initialise Action Plugins within a lane:
                      use the lua function 'pcall' to debug the call to: package.loadlib("fullpath\\to\\pluginfilename.ext" ,"dll exported function")]];

                      --eg to initialise the memory action plugin within a lane:

                      local bool, err = pcall(package.loadlib(_SourceFolder.."\\Data\\AMSW Memory.lmd", "irPlg_Action_RegisterActions"));

                      --Debug:
                      if bool == false or err then
                      Dialog.Message("Memory: "..tostring(bool), tostring(err)); --delete me
                      -- oops, package did not load properly, bug out here !
                      end


                      --initialise the luacom action plugin (either of below "exported functions" for luacom will work):

                      local bool, err = pcall(package.loadlib(_SourceFolder.."\\Data\\LuaC om.lmd", "irPlg_Action_RegisterActions"));
                      --local bool, err = pcall(package.loadlib(_SourceFolder.."\\Data\\LuaC om.lmd", "luacom_open"));

                      --Debug:
                      if bool == false or err then
                      Dialog.Message("Luacom: "..tostring(bool), tostring(err)); --delete me

                      -- oops, package did not load properly, bug out here !
                      end


                      --initialise the WinApi action plugin (make sure all constants for this plugin are avaliable):

                      local bool, err = pcall(package.loadlib(_SourceFolder.."\\Data\\WinA pi.lmd", "irPlg_Action_RegisterActions"));
                      --Debug:
                      if bool == false or err then
                      Dialog.Message("WinApi: "..tostring(bool), tostring(err)); --delete me

                      -- oops, package did not load properly, bug out here !
                      end




                      --[[TipS: make use of collectgarbage(); Memory = nil; luacom = nil; WinApi = nil; blahblah = nil; etc.
                      within lane fuctions before a lane returns to ensure lane closes properly(reclaim some memory for System)

                      Application.GetWndHandle(); does not return properly within a lane, experiment with what you need
                      of course have the _G (globals table) filled with values you need prior to calling a lane ..
                      DLL.CallFunction(etc.); works within a lane (or use the memory plugin)]];

                      --[[Have not tried any Object plugins within a lane however the 'exported functions' for standard Object plugins:

                      "irPlg_Object_CreateObject"
                      "irPlg_Object_DeleteObject"
                      "irPlg_Object_TranslateMessage"
                      --if has fonts:
                      "irPlg_Object_GetFonts"

                      ]];

                      so try:

                      local bool, err = pcall(package.loadlib("futhpathtoPlugin", "irPlg_Action_RegisterActions"));

                      Comment


                      • #12
                        I could not find the example, but the main idea when using linda objects is:

                        - Create a linda object before you create any new lane, like this
                        PHP Code:
                        linda lanes.linda(); 
                        - Setup a Page.Timer (the interval is up to you) that reads any linda message received. I recommend to use linda:get instead of linda:receive because linda:get is a non-consuming method:
                        PHP Code:
                        local value linda.get("aKey");
                        if(
                        valuethen
                          
                        --// Do something like MemoryEx.Free(t)
                        end 
                        - Inside your lane, set the key an value when you need it:
                        PHP Code:
                        linda:set("aKey"true); 

                        Comment


                        • #13
                          a little test code works within a lane at my end with IP's MemoryEx plugin,
                          using lanes module version 2.2 and latest MemoryEx plugin

                          Code:
                          local bool, err = pcall(package.loadlib(_SourceFolder.."\\Data\\MemoryEx.lmd", "irPlg_Action_RegisterActions"));
                              Dialog.Message(tostring(bool), tostring(err));
                              local hBuffer = MemoryEx.AllocateEx(1024);
                          	if(hBuffer)then
                            		local ptr = hBuffer:GetPointer();
                            		Dialog.Message("pointer: oop method", tostring(ptr));
                            		-- Do stuff with the pointer here, like providing it to a WinApi function.
                             		hBuffer:Free();
                          	end

                          Comment


                          • #14
                            thanks guys, package.loadlib works just fine so what's the story with that anyway? I use Application.LoadActionPlugin so I don't need to have the Plugins folder so is package.loadlib cool to use for all action plugins and can we use it for object plugins to get rid of them from the Plugins folder too?

                            Not able to get the contents of the LH modules in the Lane without re loading it in the Lane but its no big deal as I can make mini LH files just for that purpose.

                            Comment


                            • #15
                              glad the basics are solved..have not tried with any object plugins so can't help there.

                              I did reasonable testing with the popular action plugins a while back and all worked without issue

                              a little trick i have used is to modify the default 'require' search path and file extension path as well:

                              Code:
                              package.cpath = '.\\Data\\?.da_;?.da_;'..string.gsub(package.cpath, 'dll', 'da_');
                                  package.path = '.\\Data\\?.la_;?.la_;'..string.gsub(package.path, 'lua', 'la_');
                              sometimes the lua call package.seeall can help too eg:

                              [CODE]require "lfs";--lua file system module
                              module("lfs", package.seeall)[CODE]

                              Comment

                              Working...
                              X
                              😀
                              🥰
                              🤢
                              😎
                              😡
                              👍
                              👎