Jump to content
Tuts 4 You

Using Lua shellexecute to open a website


STN

Recommended Posts

Posted (edited)

Hey everyone, its been a long time since i was last here so sorry if it is in the wrong section.

 

I am pretty new to Lua and its not my language of choice but its the only language this program allows so i am stuck. I am trying to open a website using shellexecute in Lua but no matter what i do, i don't seem to get any results when the script runs. I have been googling for hours now and there were a few good reads but apparently i am the only one who is using shellexecute to open website or maybe no one else has this problem, there were a few examples using native os function (os.execute) but they didn't seem to work either for me, it just opened a cmd window without actually opening the website

This is my code

shellExecute("open", "deviatted")

i even tried variations such as shellExecute("open",nil,http://deviatted.com/)

but it isn't working at all. It would help if there was a MSDN like library for Lua with various examples that quickly show the syntax etc. 

 

I am pretty sure i am missing something obvious here and after hours of headbanging, i have come to you genius bunch for help :).

Edited by STN
  • Like 1
Posted (edited)

For one, Lua does not come stock with any sort of 'shellexecute' function. Nor does it come stock with any API exposure to the systems API.

 

If you are looking to make calls to API, then you either need to:

  • Expose a function wrapper to Lua to be able to call the API from a script.
  • Import and use a library such as Alien to make system API calls.
Exposing a function requires you to write a wrapper and set the name of it inside the Lua state.

 

static int lua_ShellExecute( lua_State* pState ){    auto command = luaL_checkstring( pState, -2 );    auto path = luaL_checkstring( pState, -1 );        ShellExecute( NULL, command, path, NULL, NULL, SW_SHOWNORMAL );        return 0;}
After that you have to expose it to Lua with:
lua_register(pState, "shellExecute", lua_ShellExecute);
Edited by atom0s
Posted (edited)

@atom0s: Thanks for the detailed response, i solved it by using Lua execute command (os.execute'start url' ) much smaller code but i will keep your code in mind, gonna be useful when i understand what it actually does and learn more than how to write a hello world program in Lua lol.


 


@Dreamer: I came across that article when i was Googling earlier but it was too hard for me to comprehend and i kept getting errors. Its only like 2 hours total that i've touched Lua and the syntax is different than C which is what i code mostly in. Thanks for the help anyway :).


Edited by STN

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...