[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: lua-l Digest, Vol 14, Issue 58
- From: <AllanPfalzgraf@...>
- Date: Thu, 15 Sep 2011 17:14:17 -0400
I've double-checked, rebuilt the cb.dll using the lua5.1.lib from the same release directory as the lua5.1.dll.
I've added a gpLuaState = L; in cbNewData.
The Eaton filters block the use of Pastebin, I'd be willing to check out other means of file sharing.
Good suggestions, but so far no change in the behavior.
-----Original Message-----
From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of lua-l-request@lists.lua.org
Sent: Thursday, September 15, 2011 2:01 PM
To: lua-l@lists.lua.org
Subject: lua-l Digest, Vol 14, Issue 58
Send lua-l mailing list submissions to
lua-l@lists.lua.org
To subscribe or unsubscribe via the World Wide Web, visit
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org
or, via email, send a message with subject or body 'help' to
lua-l-request@lists.lua.org
You can reach the person managing the list at
lua-l-owner@lists.lua.org
When replying, please edit your Subject line so it is more specific than "Re: Contents of lua-l digest..."
Today's Topics:
1. Re: Asynchronous callback (Duncan Cross)
2. Asynchronous callback - no attachments (AllanPfalzgraf@eaton.com)
3. Asynchronous callback - no attachments (AllanPfalzgraf@eaton.com)
4. Re: Asynchronous callback - no attachments (HyperHacker)
5. Re: Asynchronous callback - no attachments (Rob Hoelz)
----------------------------------------------------------------------
Message: 1
Date: Thu, 15 Sep 2011 19:33:18 +0100
From: Duncan Cross <duncan.cross@gmail.com>
Subject: Re: Asynchronous callback
To: Lua mailing list <lua-l@lists.lua.org>
Message-ID:
<CAChYW+w4G=q2pH_9NK3q3iWHBKvnEYof25N4ejdYtSXpaBX1ZQ@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Sep 15, 2011 at 6:55 PM, <AllanPfalzgraf@eaton.com> wrote:
> (...) However, it fails when the table is declared and Lua is
> terminated.
>> --Indirect Use
>> cb.write(18,19,20)
> callback 18 19 20
> table
> 3
>
> I am unable to understand how the execution can be different in the
> cbq.lua file depending on the means of calling a function. It is
> clear that the cbCallback function is executing, it just fails
> internally. (...)
I'm not able to try running your code properly for myself at the moment but just from the sound of this: I recommend making sure that your C module is definitely being dynamically linked to the same Lua core (i.e. lua5.1.dll/lua5.1.so) as the command line application is using. If it isn't, I think that would explain why a table allocation by the module would fail and bring down the application.
-Duncan
------------------------------
Message: 2
Date: Thu, 15 Sep 2011 14:34:38 -0400
From: <AllanPfalzgraf@eaton.com>
Subject: Asynchronous callback - no attachments
To: <lua-l@lists.lua.org>
Message-ID:
<4FC6198A618792428E917F64FC7E5915046FBF6D@CLEOHSMB03.napa.ad.etn.com>
Content-Type: text/plain; charset="utf-8"
Below is the content of a small library that simulates the behavior of software that produces asynchronous data. This library is intended to move that data into the data space of a Lua script.
If the Lua function that is called in fnCallback is called directly from Lua it works, if it is called via fnCallback it fails when the table is declared for storage of the three parameters. (see the console output near the end of this email)
Appologies for the length of this, it could not have been made shorter.
-- Essential code for the cb.dll -----------------------------------
static lua_State *gpLuaState = 0; // Used by callback function to send status to the script.
static int cbNewData( lua_State * );
void fnCallback( int, int, int );
static int cbNewData( lua_State *L )
{
int a, b, c;
a = luaL_checkint( L, 1 );
b = luaL_checkint( L, 2 );
c = luaL_checkint( L, 3 );
fnCallback( a, b, c );
return 0;
}
void fnCallback( int nEvent, int nParam1, int nParam2 ) { int stat;
if (gpLuaState != 0)
{
lua_getglobal( gpLuaState, "cbCallback" );
lua_pushinteger( gpLuaState, nEvent );
lua_pushinteger( gpLuaState, nParam1 );
lua_pushinteger( gpLuaState, nParam2 );
// do the call ( 3 arguments, no return, no error function )
if (stat = lua_pcall( gpLuaState, 3, 0, 0 ) != 0 )
{
printf("eipCallback failed, code %d - %s", stat, lua_tostring(gpLuaState, -1));
lua_pop(gpLuaState, 1);
}
}
else
{
printf("gpLuaState was not initialized"); } }
static const luaL_Reg cblib[] = {
{"write", cbNewData},
{NULL, NULL}
};
LUALIB_API int luaopen_cb (lua_State *L) {
gpLuaState = L;
/* open library */
luaL_register(L, "cb", cblib);
return 1;
}
-- Contents of cbq.lua -----------------------------------
FAILURE = 1
SUCCESS = 0
q = {first = 1,
last = 0,
list={}
}
function cbCallback(event, param1, param2) local last = q.last + 1 q.last = last print("callback",event, param1, param2)
print(type(q.list))
print(last)
q.list[last] = {}
print(type(q.list[last]))
q.list[last][1]=event
print(q.list[last][1])
q.list[last][2]=param1
print(q.list[last][2])
q.list[last][3]=param2
print(q.list[last][3])
end
function pop()
local first = q.first
local event, param1, param2
if first > q.last then
return FAILURE
end
event = q.list[first][1]
param1 = q.list[first][2]
param2 = q.list[first][3]
print("pop",event, param1, param2)
q.list[first] = nil
q.first = first + 1
return SUCCESS, event, param1, param2
end
-- Console output of test ---------------------------------------
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require"cb"
> require"cbq"
>
> -- Direct Use
> cbCallback(12,13,14)
callback 12 13 14
table
1
table
12
13
14
> cbCallback(15,16,17)
callback 15 16 17
table
2
table
15
16
17
> print(pop())
pop 12 13 14
0 12 13 14
> print(pop())
pop 15 16 17
0 15 16 17
> print(pop())
1
> --Indirect Use
> cb.write(18,19,20)
callback 18 19 20
table
3
Thanks in advance for any suggestions.
Allan Pfalzgraf
EATON
4201 North 27 Street
Milwaukee, WI 53216
tel: 414 449-6872
fax: 414 449-6616
AllanPfalzgraf@eaton.com
www.Eaton.com <http://www.eaton.com/> <http://www.eaton.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://vlists.pepperfish.net/cgi-bin/mailman/private/lua-l-lists.lua.org/attachments/20110915/2ec68c70/attachment-0001.html
------------------------------
Message: 3
Date: Thu, 15 Sep 2011 14:49:35 -0400
From: <AllanPfalzgraf@eaton.com>
Subject: Asynchronous callback - no attachments
To: <lua-l@lists.lua.org>
Message-ID:
<4FC6198A618792428E917F64FC7E5915046FBFA9@CLEOHSMB03.napa.ad.etn.com>
Content-Type: text/plain; charset="utf-8"
Below is the content of a small library that simulates the behavior of software that produces asynchronous data. This library is intended to move that data into the data space of a Lua script.
If the Lua function that is called in fnCallback is called directly from Lua it works, if it is called via fnCallback it fails when the table is declared for storage of the three parameters. (see the console output near the end of this email)
Appologies for the length of this, it could not have been made shorter.
-- Essential code for the cb.dll -----------------------------------
static lua_State *gpLuaState = 0; // Used by callback function to send status to the script.
static int cbNewData( lua_State * );
void fnCallback( int, int, int );
static int cbNewData( lua_State *L )
{
int a, b, c;
a = luaL_checkint( L, 1 );
b = luaL_checkint( L, 2 );
c = luaL_checkint( L, 3 );
fnCallback( a, b, c );
return 0;
}
void fnCallback( int nEvent, int nParam1, int nParam2 ) { int stat;
if (gpLuaState != 0)
{
lua_getglobal( gpLuaState, "cbCallback" );
lua_pushinteger( gpLuaState, nEvent );
lua_pushinteger( gpLuaState, nParam1 );
lua_pushinteger( gpLuaState, nParam2 );
// do the call ( 3 arguments, no return, no error function )
if (stat = lua_pcall( gpLuaState, 3, 0, 0 ) != 0 )
{
printf("eipCallback failed, code %d - %s", stat, lua_tostring(gpLuaState, -1));
lua_pop(gpLuaState, 1);
}
}
else
{
printf("gpLuaState was not initialized"); } }
static const luaL_Reg cblib[] = {
{"write", cbNewData},
{NULL, NULL}
};
LUALIB_API int luaopen_cb (lua_State *L) {
gpLuaState = L;
/* open library */
luaL_register(L, "cb", cblib);
return 1;
}
-- Contents of cbq.lua -----------------------------------
FAILURE = 1
SUCCESS = 0
q = {first = 1,
last = 0,
list={}
}
function cbCallback(event, param1, param2) local last = q.last + 1 q.last = last print("callback",event, param1, param2)
print(type(q.list))
print(last)
q.list[last] = {}
print(type(q.list[last]))
q.list[last][1]=event
print(q.list[last][1])
q.list[last][2]=param1
print(q.list[last][2])
q.list[last][3]=param2
print(q.list[last][3])
end
function pop()
local first = q.first
local event, param1, param2
if first > q.last then
return FAILURE
end
event = q.list[first][1]
param1 = q.list[first][2]
param2 = q.list[first][3]
print("pop",event, param1, param2)
q.list[first] = nil
q.first = first + 1
return SUCCESS, event, param1, param2
end
-- Console output of test ---------------------------------------
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require"cb"
> require"cbq"
>
> -- Direct Use
> cbCallback(12,13,14)
callback 12 13 14
table
1
table
12
13
14
> cbCallback(15,16,17)
callback 15 16 17
table
2
table
15
16
17
> print(pop())
pop 12 13 14
0 12 13 14
> print(pop())
pop 15 16 17
0 15 16 17
> print(pop())
1
> --Indirect Use
> cb.write(18,19,20)
callback 18 19 20
table
3
Thanks in advance for any suggestions.
Allan Pfalzgraf
EATON
4201 North 27 Street
Milwaukee, WI 53216
tel: 414 449-6872
fax: 414 449-6616
AllanPfalzgraf@eaton.com
www.Eaton.com <http://www.eaton.com/> <http://www.eaton.com/>
------------------------------
Message: 4
Date: Thu, 15 Sep 2011 12:51:05 -0600
From: HyperHacker <hyperhacker@gmail.com>
Subject: Re: Asynchronous callback - no attachments
To: Lua mailing list <lua-l@lists.lua.org>
Message-ID:
<CA+rfA1QWmYJdMp9NwNV2JmHfS96RkXmW3eJE0dXWyLQJEUJC8w@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Sep 15, 2011 at 12:49, <AllanPfalzgraf@eaton.com> wrote:
>
> Below is the content of a small library that simulates the behavior of
> software that produces asynchronous data. This library is intended to
> move that data into the data space of a Lua script.
>
> If the Lua function that is called in fnCallback is called directly
> from Lua it works, if it is called via fnCallback it fails when the
> table is declared for storage of the three parameters. (see the
> console output near the end of this email)
>
> Appologies for the length of this, it could not have been made shorter.
>
Perhaps linking to files on Pastebin would be an acceptable alternative.
--
Sent from my toaster.
------------------------------
Message: 5
Date: Thu, 15 Sep 2011 13:59:45 -0500
From: Rob Hoelz <rob@hoelz.ro>
Subject: Re: Asynchronous callback - no attachments
To: lua-l@lists.lua.org
Message-ID: <20110915135945.6430bf6d@hoelz.ro>
Content-Type: text/plain; charset="us-ascii"
On Thu, 15 Sep 2011 14:34:38 -0400
<AllanPfalzgraf@eaton.com> wrote:
> Below is the content of a small library that simulates the behavior of
> software that produces asynchronous data. This library is intended to
> move that data into the data space of a Lua script.
>
> If the Lua function that is called in fnCallback is called directly
> from Lua it works, if it is called via fnCallback it fails when the
> table is declared for storage of the three parameters. (see the
> console output near the end of this email)
>
> Appologies for the length of this, it could not have been made
> shorter.
>
> -- Essential code for the cb.dll -----------------------------------
> static lua_State *gpLuaState = 0; // Used by callback function to
> send status to the script.
> static int cbNewData( lua_State * );
> void fnCallback( int, int, int );
>
> static int cbNewData( lua_State *L )
> {
> int a, b, c;
>
> a = luaL_checkint( L, 1 );
> b = luaL_checkint( L, 2 );
> c = luaL_checkint( L, 3 );
>
> fnCallback( a, b, c );
>
> return 0;
> }
>
> void fnCallback( int nEvent, int nParam1, int nParam2 )
> {
> int stat;
>
> if (gpLuaState != 0)
> {
> lua_getglobal( gpLuaState, "cbCallback" );
> lua_pushinteger( gpLuaState, nEvent );
> lua_pushinteger( gpLuaState, nParam1 );
> lua_pushinteger( gpLuaState, nParam2 );
>
> // do the call ( 3 arguments, no return, no error function )
> if (stat = lua_pcall( gpLuaState, 3, 0, 0 ) != 0 )
> {
> printf("eipCallback failed, code %d - %s", stat,
> lua_tostring(gpLuaState, -1));
> lua_pop(gpLuaState, 1);
> }
> }
> else
> {
> printf("gpLuaState was not initialized");
> }
> }
>
> static const luaL_Reg cblib[] = {
> {"write", cbNewData},
> {NULL, NULL}
> };
>
> LUALIB_API int luaopen_cb (lua_State *L) {
> gpLuaState = L;
> /* open library */
> luaL_register(L, "cb", cblib);
> return 1;
> }
>
> -- Contents of cbq.lua -----------------------------------
> FAILURE = 1
> SUCCESS = 0
>
> q = {first = 1,
> last = 0,
> list={}
> }
>
> function cbCallback(event, param1, param2)
> local last = q.last + 1
> q.last = last
> print("callback",event, param1, param2)
> print(type(q.list))
> print(last)
> q.list[last] = {}
> print(type(q.list[last]))
> q.list[last][1]=event
> print(q.list[last][1])
> q.list[last][2]=param1
> print(q.list[last][2])
> q.list[last][3]=param2
> print(q.list[last][3])
> end
>
> function pop()
> local first = q.first
> local event, param1, param2
>
> if first > q.last then
> return FAILURE
> end
>
> event = q.list[first][1]
> param1 = q.list[first][2]
> param2 = q.list[first][3]
> print("pop",event, param1, param2)
>
> q.list[first] = nil
> q.first = first + 1
>
> return SUCCESS, event, param1, param2
> end
>
> -- Console output of test ---------------------------------------
> Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> > require"cb"
> > require"cbq"
> >
> > -- Direct Use
> > cbCallback(12,13,14)
> callback 12 13 14
> table
> 1
> table
> 12
> 13
> 14
> > cbCallback(15,16,17)
> callback 15 16 17
> table
> 2
> table
> 15
> 16
> 17
> > print(pop())
> pop 12 13 14
> 0 12 13 14
> > print(pop())
> pop 15 16 17
> 0 15 16 17
> > print(pop())
> 1
> > --Indirect Use
> > cb.write(18,19,20)
> callback 18 19 20
> table
> 3
>
>
> Thanks in advance for any suggestions.
>
>
> Allan Pfalzgraf
> EATON
>
> 4201 North 27 Street
> Milwaukee, WI 53216
> tel: 414 449-6872
> fax: 414 449-6616
> AllanPfalzgraf@eaton.com
> www.Eaton.com <http://www.eaton.com/>
> <http://www.eaton.com/>
>
>
What happens if you set gpLuaState = L in cbNewData, right before
fnCallback? I realize you probably can't do this when you're running
the real asynchronous code, but I'd like to see if it solves the issue
in your example.
Also, glad to see another Wisconsinite on the list. =)
-Rob
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
Url : http://vlists.pepperfish.net/cgi-bin/mailman/private/lua-l-lists.lua.org/attachments/20110915/4bb07f79/signature.pgp
------------------------------
_______________________________________________
lua-l mailing list
lua-l@lists.lua.org
http://vlists.pepperfish.net/cgi-bin/mailman/listinfo/lua-l-lists.lua.org
End of lua-l Digest, Vol 14, Issue 58
*************************************