Can't get lua 5.1 to work.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't get lua 5.1 to work.

mempko
Hello everyone, I am using lua 5.1 on my mac os 10.4.5
For some strange reason, this simple program does nothing...meaning, it
outputs nothing.

I have also tried using luaL_loadfile where I simply have

print "hello world";

in a file and nothing prints. So I guess my question is what do I need
to do to create a proper lua state, load a script, and call a function
within the script in lua 5.1, since all examples are old.


int main (int argc, char * const argv[])
{

     lua_State* state = lua_open();

     luaL_openlibs(state);

     luaL_loadstring (state, "print \"hello world\";");

     lua_close(state);
     return 0;
}

Reply | Threaded
Open this post in threaded view
|

Re: Can't get lua 5.1 to work.

Javier Guerra Giraldez
On Saturday 18 March 2006 1:50 pm, mempko wrote:

> Hello everyone, I am using lua 5.1 on my mac os 10.4.5
> For some strange reason, this simple program does nothing...meaning, it
> outputs nothing.
>
> I have also tried using luaL_loadfile where I simply have
>
> print "hello world";
>
> in a file and nothing prints. So I guess my question is what do I need
> to do to create a proper lua state, load a script, and call a function
> within the script in lua 5.1, since all examples are old.
luaL_loadfile and luaL_loadstring only do that: load the Lua code.  you still
have to execute it.

add lua_call after loading


--
Javier

attachment0 (207 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Can't get lua 5.1 to work.

mempko
In reply to this post by mempko
mempko wrote:

> Hello everyone, I am using lua 5.1 on my mac os 10.4.5
> For some strange reason, this simple program does nothing...meaning, it
> outputs nothing.
>
> I have also tried using luaL_loadfile where I simply have
>
> print "hello world";
>
> in a file and nothing prints. So I guess my question is what do I need
> to do to create a proper lua state, load a script, and call a function
> within the script in lua 5.1, since all examples are old.
>
>
> int main (int argc, char * const argv[])
> {
>
>     lua_State* state = lua_open();
>
>     luaL_openlibs(state);
>
>     luaL_loadstring (state, "print \"hello world\";");
>
>     lua_close(state);
>     return 0;
> }
>
>

Never mind, I simply changed luaL_loadstring to luaL_dostring and it
worked :). So I guess my next question is, what is the difference
between luaL_loadstring and luaL_dostring. It seems luaL_loadstring
loads a chunk but does not execute. If this is true, then how do you go
about executing it after loading a chunck using luaL_loadstring and
luaL_loadfile. Thank you

Reply | Threaded
Open this post in threaded view
|

Re: Can't get lua 5.1 to work.

mempko
In reply to this post by Javier Guerra Giraldez
Javier Guerra wrote:

> On Saturday 18 March 2006 1:50 pm, mempko wrote:
>> Hello everyone, I am using lua 5.1 on my mac os 10.4.5
>> For some strange reason, this simple program does nothing...meaning, it
>> outputs nothing.
>>
>> I have also tried using luaL_loadfile where I simply have
>>
>> print "hello world";
>>
>> in a file and nothing prints. So I guess my question is what do I need
>> to do to create a proper lua state, load a script, and call a function
>> within the script in lua 5.1, since all examples are old.
>
> luaL_loadfile and luaL_loadstring only do that: load the Lua code.  you still
> have to execute it.
>
> add lua_call after loading
>
>

Thank you very much, that did the trick. I discovered this on my own
before reading your post. Thank you so much anyway.

Reply | Threaded
Open this post in threaded view
|

Re: Can't get lua 5.1 to work.

mempko
In reply to this post by mempko
mempko wrote:

> mempko wrote:
>> Hello everyone, I am using lua 5.1 on my mac os 10.4.5
>> For some strange reason, this simple program does nothing...meaning,
>> it outputs nothing.
>>
>> I have also tried using luaL_loadfile where I simply have
>>
>> print "hello world";
>>
>> in a file and nothing prints. So I guess my question is what do I need
>> to do to create a proper lua state, load a script, and call a function
>> within the script in lua 5.1, since all examples are old.
>>
>>
>> int main (int argc, char * const argv[])
>> {
>>
>>     lua_State* state = lua_open();
>>
>>     luaL_openlibs(state);
>>
>>     luaL_loadstring (state, "print \"hello world\";");
>>
>>     lua_close(state);
>>     return 0;
>> }
>>
>>
>
> Never mind, I simply changed luaL_loadstring to luaL_dostring and it
> worked :). So I guess my next question is, what is the difference
> between luaL_loadstring and luaL_dostring. It seems luaL_loadstring
> loads a chunk but does not execute. If this is true, then how do you go
> about executing it after loading a chunck using luaL_loadstring and
> luaL_loadfile. Thank you
>
>

Thank you Javier Guerra, You have answered my question already :)