From: <tr...@us...> - 2008-12-14 19:22:37
|
Revision: 19055 http://bzflag.svn.sourceforge.net/bzflag/?rev=19055&view=rev Author: trepan Date: 2008-12-14 19:22:34 +0000 (Sun, 14 Dec 2008) Log Message: ----------- * finished the RawLink call-outs * implemented BZ.GetWorldURL() Modified Paths: -------------- trunk/bzflag/plugins/lua/callouts.cpp trunk/bzflag/plugins/lua/rawlink.cpp Modified: trunk/bzflag/plugins/lua/callouts.cpp =================================================================== --- trunk/bzflag/plugins/lua/callouts.cpp 2008-12-14 19:22:09 UTC (rev 19054) +++ trunk/bzflag/plugins/lua/callouts.cpp 2008-12-14 19:22:34 UTC (rev 19055) @@ -629,8 +629,9 @@ static int GetWorldURL(lua_State* L) { -// const char* url; - return 0; + const bz_ApiString url = bz_getClientWorldDownloadURL(); + lua_pushstring(L, url.c_str()); + return 1; } Modified: trunk/bzflag/plugins/lua/rawlink.cpp =================================================================== --- trunk/bzflag/plugins/lua/rawlink.cpp 2008-12-14 19:22:09 UTC (rev 19054) +++ trunk/bzflag/plugins/lua/rawlink.cpp 2008-12-14 19:22:34 UTC (rev 19055) @@ -18,8 +18,11 @@ static int AttachRawLink(lua_State* L); static int DetachRawLink(lua_State* L); -static int RawLinkWrite(lua_State* L); -static int RawLinkDisconnect(lua_State* L); +static int DisconnectRawLink(lua_State* L); +static int WriteRawLink(lua_State* L); +static int GetRawLinkIP(lua_State* L); +static int GetRawLinkHost(lua_State* L); +static int GetRawLinkQueued(lua_State* L); class Link; @@ -59,14 +62,14 @@ if (!bz_registerNonPlayerConnectionHandler(id, this)) { return; } - if (!lua_isfunction(L, 2)) { - return; + + if (lua_isnil(L, 2)) { + funcRef = LUA_REFNIL; } - - funcRef = luaL_ref(L, LUA_REGISTRYINDEX); - - if (lua_isfunction(L, 3)) { + else if (lua_isfunction(L, 2)) { funcRef = luaL_ref(L, LUA_REGISTRYINDEX); + } + else { return; } @@ -90,6 +93,9 @@ if (L == NULL) { return; } + if (funcRef == LUA_REFNIL) { + return; + } lua_checkstack(L, 4); @@ -141,14 +147,26 @@ lua_pushcfunction(L, DetachRawLink); lua_rawset(L, -3); - lua_pushliteral(L, "RawLinkWrite"); - lua_pushcfunction(L, RawLinkWrite); + lua_pushliteral(L, "WriteRawLink"); + lua_pushcfunction(L, WriteRawLink); lua_rawset(L, -3); - lua_pushliteral(L, "RawLinkDisconnect"); - lua_pushcfunction(L, RawLinkDisconnect); + lua_pushliteral(L, "DisconnectRawLink"); + lua_pushcfunction(L, DisconnectRawLink); lua_rawset(L, -3); + lua_pushliteral(L, "GetRawLinkIP"); + lua_pushcfunction(L, GetRawLinkIP); + lua_rawset(L, -3); + + lua_pushliteral(L, "GetRawLinkHost"); + lua_pushcfunction(L, GetRawLinkHost); + lua_rawset(L, -3); + + lua_pushliteral(L, "GetRawLinkQueued"); + lua_pushcfunction(L, GetRawLinkQueued); + lua_rawset(L, -3); + return true; } @@ -176,8 +194,9 @@ static int AttachRawLink(lua_State* L) { const int linkID = luaL_checkint(L, 1); - if (!lua_isfunction(L, 2)) { - luaL_error(L, "expected a function"); + + if (!lua_isnoneornil(L, 2) && !lua_isfunction(L, 2)) { + return 0; } lua_settop(L, 2); // discard any extras @@ -207,29 +226,62 @@ } -static int RawLinkDisconnect(lua_State* L) +static int WriteRawLink(lua_State* L) { const int linkID = luaL_checkint(L, 1); if (links.find(linkID) == links.end()) { return 0; } + size_t size; + const char* data = luaL_checklstring(L, 2, &size); + lua_pushboolean(L, bz_sendNonPlayerData(linkID, data, size)); + return 1; +} + + +static int DisconnectRawLink(lua_State* L) +{ + const int linkID = luaL_checkint(L, 1); + if (links.find(linkID) == links.end()) { + return 0; + } lua_pushboolean(L, bz_disconnectNonPlayerConnection(linkID)); return 1; } -static int RawLinkWrite(lua_State* L) +static int GetRawLinkIP(lua_State* L) { const int linkID = luaL_checkint(L, 1); if (links.find(linkID) == links.end()) { return 0; } - size_t size; - const char* data = luaL_checklstring(L, 2, &size); - lua_pushboolean(L, bz_sendNonPlayerData(linkID, data, size)); + lua_pushstring(L, bz_getNonPlayerConnectionIP(linkID)); return 1; } +static int GetRawLinkHost(lua_State* L) +{ + const int linkID = luaL_checkint(L, 1); + if (links.find(linkID) == links.end()) { + return 0; + } + lua_pushstring(L, bz_getNonPlayerConnectionHost(linkID)); + return 1; +} + + +static int GetRawLinkQueued(lua_State* L) +{ + const int linkID = luaL_checkint(L, 1); + if (links.find(linkID) == links.end()) { + return 0; + } + lua_pushinteger(L, bz_getNonPlayerConnectionOutboundPacketCount(linkID)); + return 1; +} + + /******************************************************************************/ /******************************************************************************/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |