From fa17009297d2ac9b30c1b1f1d8d8779c70b41105 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Mon, 13 Aug 2007 02:17:46 +0000 Subject: [PATCH] Include functions in namespaces like lua. --- stepmania/src/LuaManager.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 4f58c6f51c..7f00848d52 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -510,7 +510,6 @@ XNode *LuaHelpers::GetLuaInformation() XNode *pEnumsNode = pLuaNode->AppendChild( "Enums" ); XNode *pConstantsNode = pLuaNode->AppendChild( "Constants" ); - // Tricky. We have to get the classes from lua. vector vFunctions; map mClasses; map mSingletons; @@ -583,6 +582,32 @@ XNode *LuaHelpers::GetLuaInformation() break; } } + + // Find namespaces + lua_pushcfunction( L, luaopen_package ); lua_call( L, 0, 0 ); + lua_getglobal( L, "package" ); + ASSERT( lua_istable(L, -1) ); + lua_getfield( L, -1, "loaded" ); + ASSERT( lua_istable(L, -1) ); + + const RString BuiltInPackages[] = { "_G", "coroutine", "debug", "math", "package", "string", "table" }; + const RString *const end = BuiltInPackages+ARRAYLEN(BuiltInPackages); + FOREACH_LUATABLE( L, -1 ) + { + RString sNamespace; + LuaHelpers::Pop( L, sNamespace ); + if( find(BuiltInPackages, end, sNamespace) != end ) + continue; + + FOREACH_LUATABLE( L, -1 ) + { + RString sFunction; + LuaHelpers::Pop( L, sFunction ); + vFunctions.push_back( ssprintf("%s.%s", sNamespace.c_str(), sFunction.c_str()) ); + } + } + lua_pop( L, 2 ); + LUA->Release( L ); sort( vFunctions.begin(), vFunctions.end() );