full lua API access!
Moderators: Víctor Paredes, Belgarath, slowtiger
full lua API access!
i am impressed !
moho gives access to the WHOLE lua api!
i just tested it :
print( "PATH:", os.getenv ("PATH") )
it works!!
so the doc is here :
http://www.lua.org/manual/5.0/manual.html
Will add a script to run autotrace on bitmap files and import resulting eps.
thank you LM!
moho gives access to the WHOLE lua api!
i just tested it :
print( "PATH:", os.getenv ("PATH") )
it works!!
so the doc is here :
http://www.lua.org/manual/5.0/manual.html
Will add a script to run autotrace on bitmap files and import resulting eps.
thank you LM!
Hey 7f!
well i am just using the usual manual and tutorial
http://lua-users.org/wiki/
http://lua-users.org/wiki/TutorialDirectory
http://www.lua.org/manual/5.0/manual.html
Are you looking for something specific?
well i am just using the usual manual and tutorial
http://lua-users.org/wiki/
http://lua-users.org/wiki/TutorialDirectory
http://www.lua.org/manual/5.0/manual.html
Are you looking for something specific?
Sorry, I meant for the win32 (OS) API. I had made a tweak of the freehand script, one of the differences was that the tool would produce fewer points the faster a line was being drawn. The only only timer I could get at was the os.clock() one in lua, which seemed to be counting clock cycles for the current thread, which made it not too consistent. Theres a Lua binding for the w32 API, apparently, over ay LuaForge, but I coudn't find any info on what calls it supports. Or for that matter, what calls are available (I know it's huge). Which Lib is in which DLL, stuff like that. Thought you might have an idea, saw some of those bit's of c++ code in comments in one of your scripts.
The other problem I'm having a problem with is how to set up variable to communicate back and forth with Lua. As as example, I found a couple of pretty nifty color picker DLL's that I thought would be handy. The both wanted to return single bytes for the RGB data (and A in one case, that one returned as type boolean - don't really know c++ so I don't know what to make of that). The first, and simpler one I liked for this purpose worked fine until it wanted to return. Wanted to send back the data by reference, which seemed to make Moho very, very unhappy. The second was a nonstarter as I guess I just wasn't passing it anything it liked. I'm not sure how to make Lua's "whatever" data typing work outside of Lua.
Hell, there's plenty of stuff I'd like to do, but I'm just getting comfortable with Lua. Ah well, I'll figure it out eventually.
The other problem I'm having a problem with is how to set up variable to communicate back and forth with Lua. As as example, I found a couple of pretty nifty color picker DLL's that I thought would be handy. The both wanted to return single bytes for the RGB data (and A in one case, that one returned as type boolean - don't really know c++ so I don't know what to make of that). The first, and simpler one I liked for this purpose worked fine until it wanted to return. Wanted to send back the data by reference, which seemed to make Moho very, very unhappy. The second was a nonstarter as I guess I just wasn't passing it anything it liked. I'm not sure how to make Lua's "whatever" data typing work outside of Lua.
Hell, there's plenty of stuff I'd like to do, but I'm just getting comfortable with Lua. Ah well, I'll figure it out eventually.
hey 7feet!
i wasn't even aware that we could use our own dll with moho embeded lua interpreter! Can you tell me more about this?
I am new to lua though i know some c++/interpreted language bindings (such as tcl). Actually I do all i need to do with the lua api as it is though..
I agree there is not much lua documentation online, compared to tcl and others...
PS :
did you look in lua source code for your requests? that's the best place to know about lua!
i wasn't even aware that we could use our own dll with moho embeded lua interpreter! Can you tell me more about this?
I am new to lua though i know some c++/interpreted language bindings (such as tcl). Actually I do all i need to do with the lua api as it is though..
I agree there is not much lua documentation online, compared to tcl and others...
PS :
did you look in lua source code for your requests? that's the best place to know about lua!
LuaThread may be interesting for you
http://www.cs.princeton.edu/~diego/prof ... luathread/
but i am afraid it would implie recompiling with moho source...
(i guess the whole programe would have to be multithreaded then)
I found it on this usefull page :
his page http://lua-users.org/wiki/LibrariesAndBindings
http://www.cs.princeton.edu/~diego/prof ... luathread/
but i am afraid it would implie recompiling with moho source...
(i guess the whole programe would have to be multithreaded then)
I found it on this usefull page :
his page http://lua-users.org/wiki/LibrariesAndBindings
apparently and according to
http://lua-users.org/wiki/CppLuaArgumentPassingTutorial
you should use C functions (lua_pushnumber(), etc) to convert your arguments to lua types..
About color though they are often stored in 4 byte and it can be tricky to convert them to 0-255 int as you need to use shift operators << >>, something like :
int RGBAval = ((r << 24) | (g << 16) | (b << 8) | a)
int r = (RGBAval >>24)
int g = ((RGBAval >>16) & 0xF)
int b = ((RGBAval >>8) & 0xF)
int a = (RGBAval & 0xF))
(hum not sure...)
Can you post some example?
http://lua-users.org/wiki/CppLuaArgumentPassingTutorial
you should use C functions (lua_pushnumber(), etc) to convert your arguments to lua types..
About color though they are often stored in 4 byte and it can be tricky to convert them to 0-255 int as you need to use shift operators << >>, something like :
int RGBAval = ((r << 24) | (g << 16) | (b << 8) | a)
int r = (RGBAval >>24)
int g = ((RGBAval >>16) & 0xF)
int b = ((RGBAval >>8) & 0xF)
int a = (RGBAval & 0xF))
(hum not sure...)
Can you post some example?
What I had used was
Loadlib to pick the library, and the name of the function you want to call (in quotes). I can't recall where I got the DLL, my computer had a meltdown last night (while trying to do some data recovery for someone else - Ack!) so I can't check the history. Anyway, simple DLL with one function in it. Called correctly, looked fine, but crashed Moho with a "cannot read memory" error when I tried to send the colors back. That was the one that wanted the RGB vals by reference. On that part I'm clueless.
I was wondering if defining the variables as 1 character strings would work, or maybe a 3 of 4 character string and then just pull out the individual bytecodes. That tutorial is meant for a C++ program with Lua embedded (like Moho). The problem here is going right from Lua to external code. Since every number inside Lua is a dword float, I figure that something that's expecting a strictly typed variabe won't work well. Thats why I thought the string bit might be a useable workaround. Dunno.
Also, if you haven't checked it out yet, the online copy of the Programming in Lua that they have over at Lua.org has been very helpful for me.
Code: Select all
function SF_ColorPick:Run()
dllPath = os.getenv ("WINDIR").."\\system32\\colorpicker.dll"
local ColorPicker = assert(loadlib(dllPath),"pickcolor")
self.red,self.green,self.blue = colorPicker()
end
I was wondering if defining the variables as 1 character strings would work, or maybe a 3 of 4 character string and then just pull out the individual bytecodes. That tutorial is meant for a C++ program with Lua embedded (like Moho). The problem here is going right from Lua to external code. Since every number inside Lua is a dword float, I figure that something that's expecting a strictly typed variabe won't work well. Thats why I thought the string bit might be a useable workaround. Dunno.
Also, if you haven't checked it out yet, the online copy of the Programming in Lua that they have over at Lua.org has been very helpful for me.
Sorry to answer this old topic, but now I am playing with Lua to extend it with some C functions in a library, so I know what is the problem. Lua can receive return values from a C function only if it puts the values to the special stack of Lua. So it won't work with normal functions of normal dlls, only with those designed specially for Lua. So you have to write a dll function in C if you want to call the ColorPicker(), make something like this:
By the way, it seems the loadlib() support is not working in Moho 5.4, at least under Linux...
Code: Select all
// From http://www.linxexplorer.com/colorpickerSDK.html
////////////////////////////////////////////////////////////////////////////////////////////
// C++ sample on how to open Visual Color Picker dialog
//
class CColorRGBA
{
public:
CColorRGBA()
{
ASSERT(sizeof(CColorRGBA) == 4);
b = g = r = a = 0;
}
BYTE b, g, r, a;
};
typedef UINT (*PickColor)(CWnd *pParent, CColorRGBA & colText, CColorRGBA & colBk);
static int PickRGBColor(lua_State *L)
{
CColorRGBA colText;
CColorRGBA colBk;
// Load Visual Color Picker DLL
HINSTANCE hModule = ::LoadLibrary(_T("ColorPicker.dll"));
if (!hModule)
return (UINT)-1;
// Get Visual Color Picker function
PickColor func = (PickColor)::GetProcAddress(hModule, "PickColor");
if (!func)
{
::FreeLibrary(hModule);
return 0;
}
// call Visual Color Picker dialog function
UINT ret = func(NULL, &colText, &colBk); // returns IDCANCEL, IDOK
::FreeLibrary(hModule);
lua_pushnumber(L, ret >> 16);
lua_pushnumber(L, (ret >> 8) & 0xFF);
lua_pushnumber(L, ret & 0xFF);
return 3;
}
//
// end of sample code.
////////////////////////////////////////////////////////////////////////////////////////////
- - - Fazek
Well, that's mighty handy to know. As I can't program in C to save my life, but can perhaps puzzle things out if I have a good chunk in front of me, that's great.
I'm not sure if it was you, Fazek, but I had noticed someone mentioning being able to use some process that was specific to Lua 5.1. I don't know if that was correct and Moho 5.4 upgraded the Lua as well, but that could be the problem. As I (vaugely) understand it Lua 5.1 handles a number of things quite differently than 5.0, including library loading. There are supposed to be some flags you can set to ensure compatibility with 5.0 you can put in there when compiling 5.1, but in this is the case perhaps that didn't happen. That might explain a few strange things that have been mentioned.
I'm not sure if it was you, Fazek, but I had noticed someone mentioning being able to use some process that was specific to Lua 5.1. I don't know if that was correct and Moho 5.4 upgraded the Lua as well, but that could be the problem. As I (vaugely) understand it Lua 5.1 handles a number of things quite differently than 5.0, including library loading. There are supposed to be some flags you can set to ensure compatibility with 5.0 you can put in there when compiling 5.1, but in this is the case perhaps that didn't happen. That might explain a few strange things that have been mentioned.
Ah, okay, I was wondering about that. Haven't really had a chance to check. That said, are you talking specifically about Linux, or is that something that Lua itself throws in there. The other day, I ran out the envirionment variables on my box that I could find what I had to play with, and didn't see that.
--Okay, just checked, and I get a nil for that from os.getenv in the standalone interpreter on my XP machine, haven't tried it in Moho, but I don't think it's set in windows itself by default. So I couldn't check it. Ah, well, it's always something.
--Okay, just checked, and I get a nil for that from os.getenv in the standalone interpreter on my XP machine, haven't tried it in Moho, but I don't think it's set in windows itself by default. So I couldn't check it. Ah, well, it's always something.