View unanswered posts | View active topics It is currently Fri May 24, 2013 9:24 am



Post new topic Reply to topic  [ 7 posts ] 
 Lua and Blackbox (Need Plugin help, Update #2: 02/10 - Code) 

Lua: Plugin, Embedded, or Not Interested?
You may select 1 option

View results

 Lua and Blackbox (Need Plugin help, Update #2: 02/10 - Code) 
Author Message
BBChild
User avatar

Joined: Sun Feb 07, 2010 9:02 pm
Posts: 7
Reply with quote
Post Lua and Blackbox (Need Plugin help, Update #2: 02/10 - Code)
Update #3:
not mentioning this in the title since its not really needed,
But this is on simi-hold for now,
got laid off a While back, so yeah, :P

also still have issues with the Lua_PATH,
if i get time im going to check QtLua and see if that will let me do what i want with less trouble,
and that being add Lua with a GUI to blackbox,

(Update#2/EDIT: Code at bottom of post.)

TODO:
    Fix the crash that happens when you disable the plugin while a lua script is running.
    Fix the only running one script at a time bit.
    Fix the paths to use a subfolder.
    Try to tie in broams.


Anyways, a problem i found, where im not sure this will be doable with a plugin,
if a script is running from the plugin, and you disable it, then close the script, blackbox crashes.
(imo a alot better the old problem of closing the script and blackbox crashing, :P)
so im not sure how to kill any running scripts or even detect them just yet,
or how to put a 'cant unload plugin while script is running' popup. -_-
But yes, it seems to be loading scripts w/o problem now.
(Still usingthe SDK / double click method though)

Also still have the 'path' problem. -_-

EDIT: Problem #3: It also seems that it'll only launch one script at a time. oi.
meaning if i double click on the pluginSDK box, the first script will run, but the second wont till i close the first one.
(Yes, i never tried this before because i was trying to stop it from crashing all the time, :P)
...And its seems to only happen once.
IE: you run blackbox, double click the plugin, first script runs, you close it, second comes up, close it, 3rd, etc,
if you do it again, only the first script runs. -_-

Mind, this is a init.lua script with 'dofile' lines.
Code:
dofile (<script #1>')
dofile ('<script #2>')
dofile ('<script #3>')

it only runs the next line after the script above it closes,
so script #1 runs, but script #2 wont till script #1 closes, and script #3 wont till #2 closes.
but after script #3 runs. If you doubleclick the box again, Only script #1 will run. #2 and #3 wont run again until blackbox is restarted.



I also thought of just having the plugin launch the little launcher program im working on, but i also found out that closing scripts sometimes leaves the .exe still running.
This also happens with the Lua.exe's so its not my fault, :P
(try running the 'calculator.wx.wlua' script from the 'wx' examples. wLua.exe will still be running after you close the script. ...least it does for me.)

this leads me to think that embedding Lua into blackbox seems be a better way to go.
then blackbox.exe can then launch the scripts and handle the cleanup instead of random .exes just running in the background after they are done being used.

So i might look into that more seriously later,
but honestly being a 'hobby' coder it was a bit of a pain just the get the pluginSDK options set with DevC++, so dont expect anything here anytime soon. :P


I Might put up the plugin if i can get the path bits set correctly.
though mind it'll be Extremely Alpha if i do.


But for now, here is semi working code that will launch one Lua script. (Called: init.lua )
which HAS to be in the directory with blackbox.exe. This means the lua.dll files have to be there also and Any thing else the script needs to run.
Yes. Im going to try to fix that.

Also,
WARNING: If you disable the plugin while a Lua script is running. Blackbox Will crash.
This is why this is code, for people that might want to mess with it, and not a release in any way:

So under the 'includes' in the bbSDK.cpp i have this:
Code:
#include <stdio.h>

extern "C"{
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}


and under the 'about_box' i have this:
Code:
/* the Lua interpreter */
lua_State* L = luaL_newstate();

void runlua (void)
{
    lua_State* L = luaL_newstate();
   
   // initialize Lua
   L = lua_open();

   // load Lua base libraries
   luaL_openlibs(L);

   // run the script
    luaL_dofile(L, "init.lua");

   /*
   'lua_gc' seems to cause memory corruption if run here.
   IE: running a GUI script, none of the buttons show till you mouse over them,
   same with text boxes and scrollbars. They dont show till used.
   
   'lua_close' crashes Blackbox when used here.
   Adding different 'newstate' seems to cause issues too.
   IE: L_M = luaL_newstate(); / lua_close(L_M);
   causes a crash with lua_close as well.
   */
   // cleanup Lua
   //lua_gc(L, LUA_GCCOLLECT, 0);
   //lua_close(L);
}

(Yes, i know im setting 'newstate' twice)


Under the Very top of the 'void endPlugin(HINSTANCE hPluginInstance)'
i have this:
Code:
    // cleanup Lua
    if ( lua_gc(L, LUA_GCCOUNT, 0) > 0)
    {
    //lua_gc(L, LUA_GCCOLLECT, 0);
    //lua_gc doesn't seem to do any good here. But im leaving it commented in anyways.
    lua_close(L);
    }

(This could probably just be 'lua_close(L);' ...but the 'GCCOUNT' was me trying to detect running scripts, and its what i have there, so its what im posting. That way if someone spots a problem its with my Actual code and not code edited for the boards.)


And in the doubleclick bit, i replace 'about_box' like so:
Code:
        case WM_LBUTTONDBLCLK:
            /* Do something here ... */
            runlua();
            break;


So if anyone else is playing with this. Have fun. :P

_________________
"It's not that I'm Evil, just that I'm unwillingly Good."
-Stolen, but oh so fitting. ^-^


Last edited by Firewrath on Thu Oct 14, 2010 12:05 pm, edited 5 times in total.



Sun Feb 07, 2010 11:15 pm
Report this post
Profile
Sponsored Links
Google Adsense


BBChild
User avatar

Joined: Sun Feb 07, 2010 9:02 pm
Posts: 7
Reply with quote
Post Org: Lua and Blackbox (Need Plugin help, Also warning, its l
Ok, moving my first post down so i can edit and keep the 1st one for updates or releases, IF that happens, (I'm still trying though, :P)
This is just to archive some the information/code and the discussion i wanted to start, while keeping the first post free.

========================================================================

Well first off. Hi, :P
ive been lurking around here for a few years, never had much of a reason to post cause i can never convince myself to keep bb installed longer then a few days*, so id just drop by to check on updates or play with plugins,
(*Nothing against BB, its just always some windows function i find out i use more then i thought i did, ...for instance the 'most used programs' bit in the start menu, handy that, :P)
And yes, my first post and its a poll, i know how that looks, -_-
I normally dont do polls, but im honestly curious what people think about the idea.

So anyways, warning, this post is a little code'y, and im ...wordy at times, so it'll be long, :P
i wanted to post this is the Dev Corner, but seems i cant or im not allowed, or something, idk,
no 'new thread' button *shrugs*
though it should fit just as well here too,

Anyways, as i said here, ive just started learning Lua, and im amazed by the unseen/unused possibilities of it,
so while playing with it and iupLua i thought itd be a Great addon to Blackbox as a plugin, OR embedded in bb to run scripts in the same way it runs plugins, or do GUI work,
(the more i fool with it, the more i think the latter)

Anyways, so i tried, and ...didnt get very far.
(Ive played with C++ for years, but theres reasons i never really get anywhere with it, -_-
so chance are ive probably screwed this up trying to implement it, ^-^;)

For some reason after running a Lua script, blackbox crashes,
i have an idea which i'll post on where it comes up in the code, but im hoping either you can guys here can help me with this, or one of you more talented coders can take off with it,

So heres how i got to what i have, i started with this:
Code:
#include <stdio.h>

extern "C"{
   #include "lua.h"
   #include "lualib.h"
   #include "lauxlib.h"
}

/* the Lua interpreter */
lua_State* L;

int main ( int argc, char *argv[] )
{
   /* initialize Lua */
   L = lua_open();

   /* load Lua base libraries */
   luaL_openlibs(L);

   /* run the script */
   luaL_dofile(L, "init.lua");

   /* cleanup Lua */
   lua_close(L);

   return 0;
}

(Yes, im using 'luaL_dofile' because for some reason 'luaL_loadfile' wont run my script)

because i cant find a script to exe compiler, i made a launcher, ...which has its own problems that also comes up in the plugin im trying to make,
so i wanted to do that in BB, after getting DevC++ to compile the pluginSKD and setup for lua,

i took the above main() funtion and replaced the about_box() funtion in the SDK, i tried to compile but kept getting this error:
Quote:
too few arguments to function `int about_box(int, char**)'

i kept the name about_box(), then i killed the int and made it back into a void, so,
void about_box(void)
got rid of the return ofcourse,

so i uncommented the about_box() function, created my own runlua() function, replaced the about_box() in the 'WM_LBUTTONDBLCLK:' bit to runlua() ...and it still crashes after running a script,

Now, im Pretty sure this is whats causing Blackbox to crash,
i mean, taking the " int argc, char *argv[] " out of the function,
but i cant figure out how to make it call the function with it,

if i leave the function like this:
Code:
int runlua( int argc, char *argv[] )


and i change the 'WM_LBUTTONDBLCLK:' like so:
Code:
        case WM_LBUTTONDBLCLK:
            /* Do something here ... */
            runlua();
            break;

it gives me this error trying to compile it:
Quote:
too few arguments to function `int runlua(int, char**)'


Ive even taken the code out of the function and placed it like so:
Code:
        case WM_LBUTTONDBLCLK:
            /* Do something here ... */
{
   /* initialize Lua */
   L = lua_open();

   /* load Lua base libraries */
   luaL_openlibs(L);

   /* run the script */
   luaL_dofile(L, "init.lua");

   /* cleanup Lua */
   lua_close(L);
}
            break;

this compiles, BUT, crashes blackbox after a script is run,

so that is problem #1, ...and the more important one because if that isnt fixed, problem two doesnt matter so much,

but problem #2 is:
it seems no matter What i do this to:
Code:
/*
** In Windows, any exclamation mark ('!') in the path is replaced by the
** path of the directory of the executable file of the current process.
*/
#define LUA_LDIR   "!\\lua\\"
#define LUA_CDIR   "!\\"
#define LUA_PATH_DEFAULT  \
      ".\\?.lua;"  LUA_LDIR"?.lua;"  LUA_LDIR"?\\init.lua;" \
                   LUA_CDIR"?.lua;"  LUA_CDIR"?\\init.lua"
#define LUA_CPATH_DEFAULT \
   ".\\?.dll;"  ".\\?51.dll;"  LUA_CDIR"?.dll;" LUA_CDIR"?51.dll;" LUA_CDIR"clibs\\?.dll;" LUA_CDIR"clibs\\?51.dll;" LUA_CDIR"loadall.dll;" LUA_CDIR"clibs\\loadall.dll"

in the 'luaconf.h'

ALL the lua scripts and .dlls Have to be in the same folder as the blackbox.exe in order to run,
(Same problem my launcher is having, -_-)
meaning i cant get it to run scripts or detect the .dlls in a subfolder,
ideally, youd want them in a subfolder of the lua-plugin folder so you can run 1-2 plugins that might launch different scripts or the same scripts where they wont interfer with each other,

Also note, i dont have lua 'installed', i just unziped the windows binarys and started playing with it,
so i dont have lua environment paths set or anything,
(Personally, i dont like installing software if i dont have to, 90% of the stuff i use comes from: The Portable Freeware Collection.)



Ok, now that im past all my problems and coding and so on, the discussion part of my post,
i'll keep this short considering the wall of text i put above, ^-^;;
while messing with this, it occurred to me, that Blackbox might be better benefited with Lua embedded, where it would run the scripts in the same manner it runs plugins,
So what do you guys think?
mebey Yet another Blackbox branch that embeds Lua?
Yes?
No?
You expect us to Read all of this? :P
*ahem* ^-^
...IS there even really a difference between a plugin and having it embedded?
i mean, could a plugin be made to mimic how blackbox runs scripts and just do it that way?
Would embedding it and using like the wx or iup dlls make doing GUI easyer?
(Yes, i know, i cant even get a plugin to work, how on earth would i embed Lua into BB, ...Truthfully, ive no clue, right now im just curious as to what everyone thinks.)

Anyways,
Sorry my first Real post is a little ...long,
...and a poll, -_-
But hopefully you guys can help me fix/improve the plugin here so itll get into a semi working order,
heh, i do not look forward to try tieing it into broams when i cant even get it compiled in the first place, -_-

_________________
"It's not that I'm Evil, just that I'm unwillingly Good."
-Stolen, but oh so fitting. ^-^


Wed Feb 10, 2010 5:27 pm
Report this post
Profile
BBDinosaur
User avatar

Joined: Tue Nov 22, 2005 6:37 pm
Posts: 232
Location: Somewhere fun with nice ladies
Reply with quote
Post Re: Lua and Blackbox (Need Plugin help, Update #2: 02/10 - Code)
are the ?'s in the path lines supposed to be regex?

_________________
It's a trick, get an axe!!!
Image


Mon Mar 15, 2010 12:57 am
Report this post
Profile YIM WWW
BBChild
User avatar

Joined: Sun Feb 07, 2010 9:02 pm
Posts: 7
Reply with quote
Post Re: Lua and Blackbox (Need Plugin help, Update #2: 02/10 - Code)
yeah, it searches for the .lua file you want to load,
ive also had it say it cant find a file, calculator.wx.wlua, and seen it was looking for a folder named calculator, and then the file as 'wx.wlua' -_-

it works when i dump Everything into a single folder though,
but i Dont want that to be the blackbox Root folder, hence why i was trying to change the paths,

i have found out that in order to change said path, i have to rebuild the lua.dlls,
which i find rather annoying, imo, if i include the luaconf.h in my program, That should override the .dlls, but it doesnt, ...or not that i can seem to get it to anyways,
(rebuilding the lua.dlls seems to be a mess in its own right, :P ... could be cause im more of a hobby programmer though, :P)

Lua 5.2 has been in testing, i might just wait to see what that changes,
eitherway, offline stuff has been interfering a bit lately, so this has gotten a little side tracked,
ive not Stopped working on it, but i might not post any progress until i get this path bit worked out, rebuild the .dlls, or find a way to fix it,

_________________
"It's not that I'm Evil, just that I'm unwillingly Good."
-Stolen, but oh so fitting. ^-^


Fri Mar 19, 2010 5:43 pm
Report this post
Profile
BBAdult

Joined: Sat Aug 21, 2010 7:44 pm
Posts: 24
Location: Sweden
Reply with quote
Post Re: Lua and Blackbox (Need Plugin help, Update #2: 02/10 - C
It been a while...

Your LUA idea is good (any idea tha pushes the development is good)

hovewer IF you are asking to embed LUA | C | TC | BASIC | PASCAL | ... into the bbWin core...

A better approach would be (as I see it) to create a "generic" script plugin, like ActiveX scripting is done... (in fact it should be ActiveX, opening up a wider market of script engines), So a generic script interface is made, the script engine register itself and its "stuff" into the bbWin script interface... then the prefered script usage is selectable by taste.

Now I do not think that this would happen, I still don't have created a plugin yet, I got your code framework and setup to work though, but my time is strongly limited.

So if any other coder out there on the bbWin read this, if you need to do future plugins for

bbWin, try make them generic and plugable, recycling is good.


And for you FireWrath, what about looking into some other code, preferable in some available script plugin?


hope someone understand my words...?

_________________

http://minaprogram.blogspot.com


Sat Jan 15, 2011 8:46 am
Report this post
Profile WWW
BBNewborn
User avatar

Joined: Sun Apr 08, 2012 5:41 am
Posts: 2
Reply with quote
Post Lua and Blackbox Need Plugin help Update #2 02/10 Code
Since it's only a beta; some files aren't viewable eventhough I added to the list. I even STOP and START the service and yet only a few came up. So I thought LUA would be my best choice.

_________________
Gotta none of it.


Fri Jun 29, 2012 6:42 am
Report this post
Profile ICQ YIM
BBChild
User avatar

Joined: Sun Feb 07, 2010 9:02 pm
Posts: 7
Reply with quote
Post Re: Lua and Blackbox (Need Plugin help, Update #2: 02/10 - C
Azvareth wrote:
It been a while...

Yes, ...Yes it has >.>
I'll be honest, I havn't touched this is a while. I lost a harddrive with around 100+gig of stuff on it, most of my programing included.
(It was all setup to be portable so I could use it on whatever computer I happened to be on.)

I also never found a way to bypass the LUA.dlls to change the directory like I wanted.

But basically, this was never ment to be something to truly embed LUA into BB, it was supposed to be a way to run LUA scripts through BB for whatever purpose. I did want to hook into bro@ms at some point to add some integration between LUA and BB, which is as close to 'embedding' as I would have gotten, but that would have been well after I got it working. :P

Really it was just a fun idea/project for me since I was playing with LUA a bit at the time, and it seemed a nice fit. Maybe if things ever pickup for BB or I get into a position where I have some time, I'll look into this again, ...Specially considering how I feel about Win8 and the Metro UI. *Shudder* ;)



Also, I agree, a generic script interface would be nice, VB script would also be a nice fit for BB to tie into windows.
I've also wanted to try AutoIT but have No clue how to hook that into BB with a plugin...
But like I said, someday I'll hopefully get back to this.

_________________
"It's not that I'm Evil, just that I'm unwillingly Good."
-Stolen, but oh so fitting. ^-^


Fri Apr 19, 2013 8:12 am
Report this post
Profile
Sponsored Links
Google Adsense


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 


Who is online

Users browsing this forum: Kspsamdwe and 1 guest


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.