Require for "Require" Support

What features you would like to have in HIDmacros?
Post Reply
luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Require for "Require" Support

Post by luiwingkin » 01 Oct 2018, 06:03

I have tried to use the command of "require" in Luamacros so as to extend the function, but get the error:

2018-10-01 13:01:18:883 [LUA] ERROR: Runtime error
error loading module 'winapi' from file 'C:\Users\WingKin\Dropbox\Small Tools\luamacros\winapi.dll':
?䤣???w?ҲաC

I think LuaMacros is responding to the command, but I have not idea about how to include the .dll file to the code because of the "?䤣???w?ҲաC" is unreadable. Any hints?

admin
Site Admin
Posts: 735
Joined: 01 Nov 2010, 13:00
Location: Prague, Czech republic
Contact:

Re: Require for "Require" Support

Post by admin » 01 Oct 2018, 08:30

This may not work like this as lua interpreter itself is plugged in to different program (luamacros.exe). Let me check if this can be somehow done...
Petr Medek
LUAmacros author

luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Re: Require for "Require" Support

Post by luiwingkin » 02 Oct 2018, 14:57

Thanks for you reply!

luiwingkin
Posts: 14
Joined: 06 Feb 2018, 05:23

Re: Require for "Require" Support

Post by luiwingkin » 05 Oct 2018, 02:35

Finally, I find an imperfect solution for the inclusion of the external library.
Due to the absence of the return from lmc_spawn(). I would use the io.popen() as the channel in getting the return value.
For instance,

function getClipboard()
program = pythonw_path
command = program_path .. "GetClipboard.py"
text = ""
--print(program .. " \"".. command .. "\"")
full_command = "Start /B " .. program .. " \"".. command .. "\""
--print(full_command)
f = assert(io.popen(full_command, "r"))
for line in f:lines() do
text = text .. line .. " \n "
--print(line)
end -- for loop
f:close()
return text
end

In fact, the function call the external python script to get the content from the clipboard and print the value. Then, the script utilizes the printed value as the return parameter. The external functions can be implemented by the third-party programming, and it acts as the function of "require".

For reference, "GetClipboard.py" is shown as below.

# -*- coding: utf-8 -*-
from __future__ import print_function
import PathCatcher
content = PathCatcher.GetClipboardText()
print(content)

The "PathCatcher" is available in

http://code.activestate.com/recipes/528 ... ck-captur/

Hope the solution helps the users with the similar needs!

Post Reply