Lua是一门脚本语言,由巴西里约热内卢天主教大学的一个研发小组创作,因其小巧和灵活备受青睐,魔兽世界和迅雷中都能看到它的身影,关于Lua更详细介绍和源代码,可以从http://www.lua.org获取。
和前者不同,PL/SQLDeveloper是一个商业软件,使用Delphi开发,用于Oracle数据库的开发和维护,因其功能的完备和易用性受到数据库应用开发着的追捧,官方站点为http://www.allroundautomations.com。该工具支持用户开发第三方插件用来扩展特殊的应用需求,插件以动态链接库的形式存在,库中需要导出插件必须支持的最小API集合,工具通过调用用户实现的插件API完成特定的任务。
本文尝试使用Lua语言粘合插件API达成通过脚本实现插件开发的目的,充分使用脚本无需编译的特性,并充分利用脚本提供的强大动态语言特性,避免插件开发者劳累于插件编译和发布过程,轻松实现个性化的应用需求。
在PL/SQL Developer安装目录下有个PlugIns目录,该目录下的DLL文件即是插件的实现动态连接库。插件最常见的任务便是和主应用程序进行交互——获取正在运行的应用程序信息,或者把加工处理的结果信息反馈给应用程序,此处的应用程序特指PL/SQL Developer进程,当然插件被应用程序激活触发后,你可以在插件中完成操作系统中允许的任何功能。
开发插件需要面对的API包括两部分,一部分需要在插件的动态链接库中提供,主程序启动后会在动态链接库中寻找这组函数,并通过调用这组函数确定动态链接库是否是有效的插件;另一部分API由主程序提供,插件的业务逻辑可以调用这组API实现和主程序的交互,主要包括菜单控制、窗口控制、和后台数据库交互等,例如你想在插件中执行一段SQL语句就需要用到这组API。
由插件导出的API最小集合只有一个函数IdentifyPlugIn,只要导出该函数并可正确调用,主程序就认为动态库是一个有效的插件。当然如果你的插件只有这么一个函数毫无意义的,你必须通过主程序的UI让用户和你的插件进行交互,其中几个较重要的函数有CreateMenuItem,OnMenuClick等。插件提供有组API称为事件API,主程序发生特定事件时会调用这组API,包括应用初始化、UI初始化、数据库连接初始化等等,这组API是让你的插件工作的驱动源,只有主程序触发了这组API,插件才能按照预期的规划执行特定代码。这组事件API大概有20几个,如OnCreate,OnActivate,OnDestroy等。另一组API为主程序提供插件的详细信息,如插件的版本、插件的作者、插件的版权等,如PlugInName,PlugInSubName,PlugInShortName等。此外主程序还提供注册外部文件系统的API,方便通过文件保存等功能改变主程序缺省的本地文件保存方案。还有一组数据导出的注册API,是你改变数据导出的缺省行为。
啰嗦许久,下面开始介绍如何将各类API组织起来使主程序和插件协同工作,这里有个由插件导出的重量级函数RegisterCallback,这个函数将主程序提供的回调函数地址保存到插件的变量中来,毕竟主程序是使用Delphi开发的,并且出于安全考虑主程序并未直接在PE中导出回调函数,而是通过RegisterCallback函数将函数指针作为参数返回给插件,插件使用函数指针变量保存函数地址。RegisterCallback没有采用函数名称传回回调函数地址,而是将回调函数进行编号,通过编号对应函数地址,这里就不得不提一下,安装目录下C++的插件头文件的回调函数编号是错误的,不知道是开发人员敷衍了事还支持使用Delphi开发插件,C++程序员很容易将其作为SDK的头文件进行扩展,这样就会导出碰壁,本人就曾经被折腾,最后才发现函数编号彻底混乱,害人啊。
RegisterCallback定义的示例如下。
void RegisterCallback(int Index, void *Addr) { switch (Index) { case 10 : (void *)IDE_MenuState = Addr; break; case 11 : (void *)IDE_Connected = Addr; break; case 12 : (void *)IDE_GetConnectionInfo = Addr; break; case 13 : (void *)IDE_GetBrowserInfo = Addr; break; } }
其中Index参数为回调函数编号,Addr参数为函数地址,此时将Addr参数保存在本地的函数指针变量中,后继代码即可使用函数指针调用该回调函数。
如下为本人定义的RegisterCallback函数,已经包含了所有公开的回调函数。
/* Let IDE setup function pointers */ void RegisterCallback(int Index, void*Addr) { FC_TRACE("RegisterCallback"); switch (Index) { case 1: SYS_Version = Addr; break; case 2: SYS_Registry = Addr; break; case 3: SYS_RootDir = Addr; break; case 4: SYS_OracleHome = Addr; break; case 5: SYS_OCIDLL = Addr; break; case 6: SYS_OCI8Mode = Addr; break; case 7: SYS_XPStyle = Addr; break; case 8: SYS_TNSNAMES = Addr; break; case 9: SYS_DelphiVersion = Addr; break; case 10: IDE_MenuState = Addr; break; case 11: IDE_Connected = Addr; break; case 12: IDE_GetConnectionInfo = Addr; break; case 13: IDE_GetBrowserInfo = Addr; break; case 14: IDE_GetWindowType = Addr; break; case 15: IDE_GetAppHandle = Addr; break; case 16: IDE_GetWindowHandle = Addr; break; case 17: IDE_GetClientHandle = Addr; break; case 18: IDE_GetChildHandle = Addr; break; case 19: IDE_Refresh = Addr; break; case 20: IDE_CreateWindow = Addr; break; case 21: IDE_OpenFile = Addr; break; case 22: IDE_SaveFile = Addr; break; case 23: IDE_Filename = Addr; break; case 24: IDE_CloseFile = Addr; break; case 25: IDE_SetReadOnly = Addr; break; case 26: IDE_GetReadOnly = Addr; break; case 27: IDE_ExecuteSQLReport = Addr; break; case 28: IDE_ReloadFile = Addr; break; case 29: IDE_SetFilename = Addr; break; case 30: IDE_GetText = Addr; break; case 31: IDE_GetSelectedText = Addr; break; case 32: IDE_GetCursorWord = Addr; break; case 33: IDE_GetEditorHandle = Addr; break; case 34: IDE_SetText = Addr; break; case 35: IDE_SetStatusMessage = Addr; break; case 36: IDE_SetErrorPosition = Addr; break; case 37: IDE_ClearErrorPositions = Addr; break; case 38: IDE_GetCursorWordPosition = Addr; break; case 39: IDE_Perform = Addr; break; case 40: SQL_Execute = Addr; break; case 41: SQL_FieldCount = Addr; break; case 42: SQL_Eof = Addr; break; case 43: SQL_Next = Addr; break; case 44: SQL_Field = Addr; break; case 45: SQL_FieldName = Addr; break; case 46: SQL_FieldIndex = Addr; break; case 47: SQL_FieldType = Addr; break; case 48: SQL_ErrorMessage = Addr; break; case 50: SQL_UsePlugInSession = Addr; break; case 51: SQL_UseDefaultSession = Addr; break; case 52: SQL_CheckConnection = Addr; break; case 53: SQL_GetDBMSGetOutput = Addr; break; case 54: SQL_SetVariable = Addr; break; case 55: SQL_GetVariable = Addr; break; case 56: SQL_ClearVariables = Addr; break; case 60: IDE_GetCustomKeywords = Addr; break; case 61: IDE_SetCustomKeywords = Addr; break; case 62: IDE_SetKeywords = Addr; break; case 63: IDE_ActivateKeywords = Addr; break; case 64: IDE_RefreshMenus = Addr; break; case 65: IDE_SetMenuName = Addr; break; case 66: IDE_SetMenuCheck = Addr; break; case 67: IDE_SetMenuVisible = Addr; break; case 68: IDE_GetMenulayout = Addr; break; case 69: IDE_CreatePopupItem = Addr; break; case 70: IDE_SetConnection = Addr; break; case 71: IDE_GetObjectInfo = Addr; break; case 72: IDE_GetBrowserItems = Addr; break; case 73: IDE_RefreshBrowser = Addr; break; case 74: IDE_GetPopupObject = Addr; break; case 75: IDE_GetPopupBrowserRoot = Addr; break; case 76: IDE_RefreshObject = Addr; break; case 77: IDE_FirstSelectedObject = Addr; break; case 78: IDE_NextSelectedObject = Addr; break; case 79: IDE_GetObjectSource = Addr; break; case 80: IDE_GetWindowCount = Addr; break; case 81: IDE_SelectWindow = Addr; break; case 82: IDE_ActivateWindow = Addr; break; case 83: IDE_WindowIsModified = Addr; break; case 84: IDE_WindowIsRunning = Addr; break; case 90: IDE_SplashCreate = Addr; break; case 91: IDE_SplashHide = Addr; break; case 92: IDE_SplashWrite = Addr; break; case 93: IDE_SplashWriteLn = Addr; break; case 94: IDE_SplashProgress = Addr; break; case 95: IDE_TemplatePath = Addr; break; case 96: IDE_ExecuteTemplate = Addr; break; case 97: IDE_GetConnectAs = Addr; break; case 98: IDE_SetConnectionAs = Addr; break; case 100: IDE_GetFileOpenMenu = Addr; break; case 101: IDE_CanSaveWindow = Addr; break; case 102: IDE_OpenFileExternal = Addr; break; case 103: IDE_GetFileTypes = Addr; break; case 104: IDE_GetDefaultExtension = Addr; break; case 105: IDE_GetFiledata = Addr; break; case 106: IDE_FileSaved = Addr; break; case 107: IDE_ShowHTML = Addr; break; case 108: IDE_RefreshHTML = Addr; break; case 109: IDE_GetProcEditExtension = Addr; break; case 110: IDE_GetWindowObject = Addr; break; case 111: IDE_FirstSelectedFile = Addr; break; case 112: IDE_NextSelectedFile = Addr; break; case 113: IDE_RefreshFileBrowser = Addr; break; case 120: IDE_KeyPress = Addr; break; case 121: IDE_GetMenuItem = Addr; break; case 122: IDE_SelectMenu = Addr; break; case 130: IDE_TranslationFile = Addr; break; case 131: IDE_TranslationLanguage = Addr; break; case 132: IDE_GetTranslatedMenuLayout = Addr; break; case 133: IDE_MainFont = Addr; break; case 134: IDE_TranslateItems = Addr; break; case 135: IDE_TranslateString = Addr; break; case 140: IDE_SaveRecoveryFiles = Addr; break; case 141: IDE_GetCursorX = Addr; break; case 142: IDE_GetCursorY = Addr; break; case 143: IDE_SetCursor = Addr; break; case 144: IDE_SetBookmark = Addr; break; case 145: IDE_ClearBookmark = Addr; break; case 146: IDE_GotoBookmark = Addr; break; case 147: IDE_GetBookmark = Addr; break; case 148: IDE_TabInfo = Addr; break; case 149: IDE_TabIndex = Addr; break; case 150: IDE_CreateToolButton = Addr; break; case 153: IDE_WindowHasEditor = Addr; break; case 160: IDE_BeautifierOptions = Addr; break; case 161: IDE_BeautifyWindow = Addr; break; case 162: IDE_BeautifyText = Addr; break; case 165: IDE_ObjectAction = Addr; break; case 166: IDE_ShowDialog = Addr; break; case 173: IDE_DebugLog = Addr; break; case 174: IDE_GetParamString = Addr; break; case 175: IDE_GetParamBool = Addr; break; case 176: IDE_GetBrowserFilter = Addr; break; case 180: IDE_CommandFeedback = Addr; break; case 190: IDE_ResultGridRowCount = Addr; break; case 191: IDE_ResultGridColCount = Addr; break; case 192: IDE_ResultGridCell = Addr; break; case 200: IDE_Authorized = Addr; break; case 201: IDE_WindowAllowed = Addr; break; case 202: IDE_Authorization = Addr; break; case 203: IDE_AuthorizationItems = Addr; break; case 204: IDE_AddAuthorizationItem = Addr; break; case 210: IDE_GetPersonalPrefSets = Addr; break; case 211: IDE_GetDefaultPrefSets = Addr; break; case 212: IDE_GetPrefAsString = Addr; break; case 213: IDE_GetPrefAsInteger = Addr; break; case 214: IDE_GetPrefAsBool = Addr; break; case 215: IDE_SetPrefAsString = Addr; break; case 216: IDE_SetPrefAsInteger = Addr; break; case 217: IDE_SetPrefAsBool = Addr; break; case 218: IDE_GetGeneralPref = Addr; break; case 219: IDE_PlugInSetting = Addr; break; case 220: IDE_GetProcOverloadCount = Addr; break; case 221: IDE_SelectProcOverloading = Addr; break; case 230: IDE_GetSessionValue = Addr; break; case 231: IDE_CheckDBVersion = Addr; break; } }
至此,已经将主程序提供的所有回调函数都保存到本地的函数指针变量,在插件中可以自由使用这些回调函数了。
Lua通常情况下通过将Lua虚拟机直接嵌入宿主程序代码的方式粘合代码,在本示例中,我们将Lua虚拟机直接嵌入上述的插件文件中。
在插件中代码执行从插件被载入开始,插件在收到主程序的事件调用时,将调用的代码转嫁到Lua脚本的执行,至此就完成脚本代码的粘合。
在C程序中调用Lua脚本的示例如下所述,首先一定一个C函数,该函数被插件的事件函数所调用,在函数中载入Lua脚本,并执行脚本中对应的方法,此处以粘合IdentifyPlugIn函数为例。
char* IdentifyPlugIn(int ID) { char* retValue; FC_TRACE("IdentifyPlugIn"); CHECK_LUA; /* Save the plugin ID in dynamic library */ SavePluginID(ID); lua_getglobal(L, "IdentifyPlugIn"); lua_pushinteger(L, ID); lua_pcall(L, 1, 1, 0); retValue = (char *)lua_tostring(L, -1); lua_pop(L, 1); return retValue; }
其中L为Lua虚拟机上下文结构指针,有该指针可实现Lua的线程安全,代码中首先查找Lua方法的名称,之后使用Lua的数据类型调用改脚本方法。
在这之前需要载入Lua脚本并穿件虚拟机,这部分代码如下所示。
luaL_dofile(L, scriptName);
其中scriptName问Lua脚本的文件名称。
另一个方向的调用时Lua脚本中调用C函数,主程序的回调函数都需要使用这个渠道完成,现以SYS_OracleHome函数为例,首先要注册该函数的名称到Lua执行上下文
RegisterRoutine(L, "SYS_OracleHome", luax_SYS_OracleHome);
Lua脚本对SYS_OracleHome的调用会转移为调用luax_SYS_OracleHome函数,一下为该函数的定义。
int luax_SYS_OracleHome(lua_State *l) { char* retValue; retValue = SYS_OracleHome(); lua_pushstring(l, retValue); return 1; }
此处调用了主程序函数指针(先前用RegisterCallback保存的地址),并使用Lua的数据类型返回函数返回值。
至此所有的粘合工作完成,可以在Lua脚本中编写脚本构造插件了。
注册全部的回调函数Lua名称。
/* Function for setup Lua virtual machine */ lua_State *SetupLuaSupport() { // By default file name convention regardless of complex situation HMODULE hModule; if (L) return L; L = lua_open(); if (L) { luaopen_base(L); luaopen_table(L); luaL_openlibs(L); luaopen_string(L); luaopen_math(L); } else { return NULL; // Initialization failed } hModule = GetModuleHandle("yap.dll"); if (hModule) { char fileName[MAX_PATH]; DWORD dwCount; memset(fileName, '\0', sizeof(fileName)); dwCount = GetModuleFileName(hModule, fileName, sizeof(fileName) / sizeof(TCHAR)); if (dwCount > 0) { char *szPos1, *szPos2; char scriptName[MAX_PATH]; memset(scriptName, '\0', sizeof(scriptName)); szPos1 = fileName; szPos2 = szPos1; while (szPos1 = strstr(szPos1, "\\")) { szPos2 = szPos1; szPos1 += 1; } strncpy(scriptName, fileName, szPos2 - fileName); strcat(scriptName, "\\yap.lua"); luaL_dofile(L, scriptName); /* Register c function begin */ /* Extra define for utilities */ RegisterRoutine(L, "ShowMessage", luax_ShowMessage); RegisterRoutine(L, "ShowMessageOption", luax_ShowMessageOption); RegisterRoutine(L, "FetchData", luax_FetchData); RegisterRoutine(L, "GetOpenFileName", luax_GetOpenFileName); RegisterRoutine(L, "GetSaveFileName", luax_GetSaveFileName); /* Auto scratch routine */ RegisterRoutine(L, "SYS_Version", luax_SYS_Version); RegisterRoutine(L, "SYS_Registry", luax_SYS_Registry); RegisterRoutine(L, "SYS_RootDir", luax_SYS_RootDir); RegisterRoutine(L, "SYS_OracleHome", luax_SYS_OracleHome); RegisterRoutine(L, "SYS_OCIDLL", luax_SYS_OCIDLL); RegisterRoutine(L, "SYS_OCI8Mode", luax_SYS_OCI8Mode); RegisterRoutine(L, "SYS_XPStyle", luax_SYS_XPStyle); RegisterRoutine(L, "SYS_TNSNAMES", luax_SYS_TNSNAMES); RegisterRoutine(L, "SYS_DelphiVersion", luax_SYS_DelphiVersion); RegisterRoutine(L, "IDE_MenuState", luax_IDE_MenuState); RegisterRoutine(L, "IDE_Connected", luax_IDE_Connected); RegisterRoutine(L, "IDE_GetConnectionInfo", luax_IDE_GetConnectionInfo); RegisterRoutine(L, "IDE_GetBrowserInfo", luax_IDE_GetBrowserInfo); RegisterRoutine(L, "IDE_GetWindowType", luax_IDE_GetWindowType); RegisterRoutine(L, "IDE_GetAppHandle", luax_IDE_GetAppHandle); RegisterRoutine(L, "IDE_GetWindowHandle", luax_IDE_GetWindowHandle); RegisterRoutine(L, "IDE_GetClientHandle", luax_IDE_GetClientHandle); RegisterRoutine(L, "IDE_GetChildHandle", luax_IDE_GetChildHandle); RegisterRoutine(L, "IDE_Refresh", luax_IDE_Refresh); RegisterRoutine(L, "IDE_CreateWindow", luax_IDE_CreateWindow); RegisterRoutine(L, "IDE_OpenFile", luax_IDE_OpenFile); RegisterRoutine(L, "IDE_SaveFile", luax_IDE_SaveFile); RegisterRoutine(L, "IDE_Filename", luax_IDE_Filename); RegisterRoutine(L, "IDE_CloseFile", luax_IDE_CloseFile); RegisterRoutine(L, "IDE_SetReadOnly", luax_IDE_SetReadOnly); RegisterRoutine(L, "IDE_GetReadOnly", luax_IDE_GetReadOnly); RegisterRoutine(L, "IDE_ExecuteSQLReport", luax_IDE_ExecuteSQLReport); RegisterRoutine(L, "IDE_ReloadFile", luax_IDE_ReloadFile); RegisterRoutine(L, "IDE_SetFilename", luax_IDE_SetFilename); RegisterRoutine(L, "IDE_GetText", luax_IDE_GetText); RegisterRoutine(L, "IDE_GetSelectedText", luax_IDE_GetSelectedText); RegisterRoutine(L, "IDE_GetCursorWord", luax_IDE_GetCursorWord); RegisterRoutine(L, "IDE_GetEditorHandle", luax_IDE_GetEditorHandle); RegisterRoutine(L, "IDE_SetText", luax_IDE_SetText); RegisterRoutine(L, "IDE_SetStatusMessage", luax_IDE_SetStatusMessage); RegisterRoutine(L, "IDE_SetErrorPosition", luax_IDE_SetErrorPosition); RegisterRoutine(L, "IDE_ClearErrorPositions", luax_IDE_ClearErrorPositions); RegisterRoutine(L, "IDE_GetCursorWordPosition", luax_IDE_GetCursorWordPosition); RegisterRoutine(L, "IDE_Perform", luax_IDE_Perform); RegisterRoutine(L, "SQL_Execute", luax_SQL_Execute); RegisterRoutine(L, "SQL_FieldCount", luax_SQL_FieldCount); RegisterRoutine(L, "SQL_Eof", luax_SQL_Eof); RegisterRoutine(L, "SQL_Next", luax_SQL_Next); RegisterRoutine(L, "SQL_Field", luax_SQL_Field); RegisterRoutine(L, "SQL_FieldName", luax_SQL_FieldName); RegisterRoutine(L, "SQL_FieldIndex", luax_SQL_FieldIndex); RegisterRoutine(L, "SQL_FieldType", luax_SQL_FieldType); RegisterRoutine(L, "SQL_ErrorMessage", luax_SQL_ErrorMessage); RegisterRoutine(L, "SQL_UsePlugInSession", luax_SQL_UsePlugInSession); RegisterRoutine(L, "SQL_UseDefaultSession", luax_SQL_UseDefaultSession); RegisterRoutine(L, "SQL_CheckConnection", luax_SQL_CheckConnection); RegisterRoutine(L, "SQL_GetDBMSGetOutput", luax_SQL_GetDBMSGetOutput); RegisterRoutine(L, "SQL_SetVariable", luax_SQL_SetVariable); RegisterRoutine(L, "SQL_GetVariable", luax_SQL_GetVariable); RegisterRoutine(L, "SQL_ClearVariables", luax_SQL_ClearVariables); RegisterRoutine(L, "IDE_GetCustomKeywords", luax_IDE_GetCustomKeywords); RegisterRoutine(L, "IDE_SetCustomKeywords", luax_IDE_SetCustomKeywords); RegisterRoutine(L, "IDE_SetKeywords", luax_IDE_SetKeywords); RegisterRoutine(L, "IDE_ActivateKeywords", luax_IDE_ActivateKeywords); RegisterRoutine(L, "IDE_RefreshMenus", luax_IDE_RefreshMenus); RegisterRoutine(L, "IDE_SetMenuName", luax_IDE_SetMenuName); RegisterRoutine(L, "IDE_SetMenuCheck", luax_IDE_SetMenuCheck); RegisterRoutine(L, "IDE_SetMenuVisible", luax_IDE_SetMenuVisible); RegisterRoutine(L, "IDE_GetMenulayout", luax_IDE_GetMenulayout); RegisterRoutine(L, "IDE_CreatePopupItem", luax_IDE_CreatePopupItem); RegisterRoutine(L, "IDE_SetConnection", luax_IDE_SetConnection); RegisterRoutine(L, "IDE_GetObjectInfo", luax_IDE_GetObjectInfo); RegisterRoutine(L, "IDE_GetBrowserItems", luax_IDE_GetBrowserItems); RegisterRoutine(L, "IDE_RefreshBrowser", luax_IDE_RefreshBrowser); RegisterRoutine(L, "IDE_GetPopupObject", luax_IDE_GetPopupObject); RegisterRoutine(L, "IDE_GetPopupBrowserRoot", luax_IDE_GetPopupBrowserRoot); RegisterRoutine(L, "IDE_RefreshObject", luax_IDE_RefreshObject); RegisterRoutine(L, "IDE_FirstSelectedObject", luax_IDE_FirstSelectedObject); RegisterRoutine(L, "IDE_NextSelectedObject", luax_IDE_NextSelectedObject); RegisterRoutine(L, "IDE_GetObjectSource", luax_IDE_GetObjectSource); RegisterRoutine(L, "IDE_GetWindowCount", luax_IDE_GetWindowCount); RegisterRoutine(L, "IDE_SelectWindow", luax_IDE_SelectWindow); RegisterRoutine(L, "IDE_ActivateWindow", luax_IDE_ActivateWindow); RegisterRoutine(L, "IDE_WindowIsModified", luax_IDE_WindowIsModified); RegisterRoutine(L, "IDE_WindowIsRunning", luax_IDE_WindowIsRunning); RegisterRoutine(L, "IDE_SplashCreate", luax_IDE_SplashCreate); RegisterRoutine(L, "IDE_SplashHide", luax_IDE_SplashHide); RegisterRoutine(L, "IDE_SplashWrite", luax_IDE_SplashWrite); RegisterRoutine(L, "IDE_SplashWriteLn", luax_IDE_SplashWriteLn); RegisterRoutine(L, "IDE_SplashProgress", luax_IDE_SplashProgress); RegisterRoutine(L, "IDE_TemplatePath", luax_IDE_TemplatePath); RegisterRoutine(L, "IDE_ExecuteTemplate", luax_IDE_ExecuteTemplate); RegisterRoutine(L, "IDE_GetConnectAs", luax_IDE_GetConnectAs); RegisterRoutine(L, "IDE_SetConnectionAs", luax_IDE_SetConnectionAs); RegisterRoutine(L, "IDE_GetFileOpenMenu", luax_IDE_GetFileOpenMenu); RegisterRoutine(L, "IDE_CanSaveWindow", luax_IDE_CanSaveWindow); RegisterRoutine(L, "IDE_OpenFileExternal", luax_IDE_OpenFileExternal); RegisterRoutine(L, "IDE_GetFileTypes", luax_IDE_GetFileTypes); RegisterRoutine(L, "IDE_GetDefaultExtension", luax_IDE_GetDefaultExtension); RegisterRoutine(L, "IDE_GetFiledata", luax_IDE_GetFiledata); RegisterRoutine(L, "IDE_FileSaved", luax_IDE_FileSaved); RegisterRoutine(L, "IDE_ShowHTML", luax_IDE_ShowHTML); RegisterRoutine(L, "IDE_RefreshHTML", luax_IDE_RefreshHTML); RegisterRoutine(L, "IDE_GetProcEditExtension", luax_IDE_GetProcEditExtension); RegisterRoutine(L, "IDE_GetWindowObject", luax_IDE_GetWindowObject); RegisterRoutine(L, "IDE_FirstSelectedFile", luax_IDE_FirstSelectedFile); RegisterRoutine(L, "IDE_NextSelectedFile", luax_IDE_NextSelectedFile); RegisterRoutine(L, "IDE_RefreshFileBrowser", luax_IDE_RefreshFileBrowser); RegisterRoutine(L, "IDE_KeyPress", luax_IDE_KeyPress); RegisterRoutine(L, "IDE_GetMenuItem", luax_IDE_GetMenuItem); RegisterRoutine(L, "IDE_SelectMenu", luax_IDE_SelectMenu); RegisterRoutine(L, "IDE_TranslationFile", luax_IDE_TranslationFile); RegisterRoutine(L, "IDE_TranslationLanguage", luax_IDE_TranslationLanguage); RegisterRoutine(L, "IDE_GetTranslatedMenuLayout", luax_IDE_GetTranslatedMenuLayout); RegisterRoutine(L, "IDE_MainFont", luax_IDE_MainFont); RegisterRoutine(L, "IDE_TranslateItems", luax_IDE_TranslateItems); RegisterRoutine(L, "IDE_TranslateString", luax_IDE_TranslateString); RegisterRoutine(L, "IDE_SaveRecoveryFiles", luax_IDE_SaveRecoveryFiles); RegisterRoutine(L, "IDE_GetCursorX", luax_IDE_GetCursorX); RegisterRoutine(L, "IDE_GetCursorY", luax_IDE_GetCursorY); RegisterRoutine(L, "IDE_SetCursor", luax_IDE_SetCursor); RegisterRoutine(L, "IDE_SetBookmark", luax_IDE_SetBookmark); RegisterRoutine(L, "IDE_ClearBookmark", luax_IDE_ClearBookmark); RegisterRoutine(L, "IDE_GotoBookmark", luax_IDE_GotoBookmark); RegisterRoutine(L, "IDE_GetBookmark", luax_IDE_GetBookmark); RegisterRoutine(L, "IDE_TabInfo", luax_IDE_TabInfo); RegisterRoutine(L, "IDE_TabIndex", luax_IDE_TabIndex); RegisterRoutine(L, "IDE_CreateToolButton", luax_IDE_CreateToolButton); RegisterRoutine(L, "IDE_WindowHasEditor", luax_IDE_WindowHasEditor); RegisterRoutine(L, "IDE_BeautifierOptions", luax_IDE_BeautifierOptions); RegisterRoutine(L, "IDE_BeautifyWindow", luax_IDE_BeautifyWindow); RegisterRoutine(L, "IDE_BeautifyText", luax_IDE_BeautifyText); RegisterRoutine(L, "IDE_ObjectAction", luax_IDE_ObjectAction); RegisterRoutine(L, "IDE_ShowDialog", luax_IDE_ShowDialog); RegisterRoutine(L, "IDE_DebugLog", luax_IDE_DebugLog); RegisterRoutine(L, "IDE_GetParamString", luax_IDE_GetParamString); RegisterRoutine(L, "IDE_GetParamBool", luax_IDE_GetParamBool); RegisterRoutine(L, "IDE_GetBrowserFilter", luax_IDE_GetBrowserFilter); RegisterRoutine(L, "IDE_CommandFeedback", luax_IDE_CommandFeedback); RegisterRoutine(L, "IDE_ResultGridRowCount", luax_IDE_ResultGridRowCount); RegisterRoutine(L, "IDE_ResultGridColCount", luax_IDE_ResultGridColCount); RegisterRoutine(L, "IDE_ResultGridCell", luax_IDE_ResultGridCell); RegisterRoutine(L, "IDE_Authorized", luax_IDE_Authorized); RegisterRoutine(L, "IDE_WindowAllowed", luax_IDE_WindowAllowed); RegisterRoutine(L, "IDE_Authorization", luax_IDE_Authorization); RegisterRoutine(L, "IDE_AuthorizationItems", luax_IDE_AuthorizationItems); RegisterRoutine(L, "IDE_AddAuthorizationItem", luax_IDE_AddAuthorizationItem); RegisterRoutine(L, "IDE_GetPersonalPrefSets", luax_IDE_GetPersonalPrefSets); RegisterRoutine(L, "IDE_GetDefaultPrefSets", luax_IDE_GetDefaultPrefSets); RegisterRoutine(L, "IDE_GetPrefAsString", luax_IDE_GetPrefAsString); RegisterRoutine(L, "IDE_GetPrefAsInteger", luax_IDE_GetPrefAsInteger); RegisterRoutine(L, "IDE_GetPrefAsBool", luax_IDE_GetPrefAsBool); RegisterRoutine(L, "IDE_SetPrefAsString", luax_IDE_SetPrefAsString); RegisterRoutine(L, "IDE_SetPrefAsInteger", luax_IDE_SetPrefAsInteger); RegisterRoutine(L, "IDE_SetPrefAsBool", luax_IDE_SetPrefAsBool); RegisterRoutine(L, "IDE_GetGeneralPref", luax_IDE_GetGeneralPref); RegisterRoutine(L, "IDE_PlugInSetting", luax_IDE_PlugInSetting); RegisterRoutine(L, "IDE_GetProcOverloadCount", luax_IDE_GetProcOverloadCount); RegisterRoutine(L, "IDE_SelectProcOverloading", luax_IDE_SelectProcOverloading); RegisterRoutine(L, "IDE_GetSessionValue", luax_IDE_GetSessionValue); RegisterRoutine(L, "IDE_CheckDBVersion", luax_IDE_CheckDBVersion); /* Register c function end */ } else { if (L) { lua_close(L); L = NULL; } } } return L; // Initialization successed }
用来转嫁Lua对C调用和C调用Lua的全部函数代码。
// Part 1,System functions & IDE functions use by Lua int luax_SYS_Version(lua_State *l) { int retValue; retValue = SYS_Version(); lua_pushinteger(l, retValue); return 1; } int luax_SYS_Registry(lua_State *l) { char* retValue; retValue = SYS_Registry(); lua_pushstring(l, retValue); return 1; } int luax_SYS_RootDir(lua_State *l) { char* retValue; retValue = SYS_RootDir(); lua_pushstring(l, retValue); return 1; } int luax_SYS_OracleHome(lua_State *l) { char* retValue; retValue = SYS_OracleHome(); lua_pushstring(l, retValue); return 1; } int luax_SYS_OCIDLL(lua_State *l) { char* retValue; retValue = SYS_OCIDLL(); lua_pushstring(l, retValue); return 1; } int luax_SYS_OCI8Mode(lua_State *l) { BOOL* retValue; retValue = SYS_OCI8Mode(); // lua_pushinteger(l,retValue); lua_pushinteger(l, (int)retValue); return 1; } int luax_SYS_XPStyle(lua_State *l) { BOOL* retValue; retValue = SYS_XPStyle(); // lua_pushinteger(l,retValue); lua_pushinteger(l, (int)retValue); return 1; } int luax_SYS_TNSNAMES(lua_State *l) { char* retValue; char* Param; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Param = (char*)lua_tostring(l, 1); retValue = SYS_TNSNAMES(Param); lua_pushstring(l, retValue); return 1; } int luax_SYS_DelphiVersion(lua_State *l) { int retValue; retValue = SYS_DelphiVersion(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_MenuState(lua_State *l) { int ID; int Index; BOOL Enabled; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Enabled = (BOOL)lua_toboolean(l, 3); IDE_MenuState(ID, Index, Enabled); return 0; } int luax_IDE_Connected(lua_State *l) { BOOL retValue; retValue = IDE_Connected(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetConnectionInfo(lua_State *l) { // char** Username; // char** Password; // char** Database; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Username = (char**)lua_topointer(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Password = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Database = (char**)lua_topointer(l, 3); // IDE_GetConnectionInfo(Username, Password, Database); // return 0; char* Username; char* Password; char* Database; IDE_GetConnectionInfo(&Username, &Password, &Database); lua_pushstring(l, Username); lua_pushstring(l, Password); lua_pushstring(l, Database); return 3; } int luax_IDE_GetBrowserInfo(lua_State *l) { // char** ObjectType; // char** ObjectOwner; // char** ObjectName; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectType = (char**)lua_topointer(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectOwner = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectName = (char**)lua_topointer(l, 3); // IDE_GetBrowserInfo(ObjectType, ObjectOwner, ObjectName); // return 0; char* ObjectType; char* ObjectOwner; char* ObjectName; IDE_GetBrowserInfo(&ObjectType, &ObjectOwner, &ObjectName); lua_pushstring(l, ObjectType); lua_pushstring(l, ObjectOwner); lua_pushstring(l, ObjectName); return 3; } int luax_IDE_GetWindowType(lua_State *l) { int retValue; retValue = IDE_GetWindowType(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetAppHandle(lua_State *l) { int retValue; retValue = IDE_GetAppHandle(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetWindowHandle(lua_State *l) { int retValue; retValue = IDE_GetWindowHandle(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetClientHandle(lua_State *l) { int retValue; retValue = IDE_GetClientHandle(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetChildHandle(lua_State *l) { int retValue; retValue = IDE_GetChildHandle(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_Refresh(lua_State *l) { IDE_Refresh(); return 0; } int luax_IDE_CreateWindow(lua_State *l) { int WindowType; char* Text; BOOL Execute; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Text = (char*)lua_tostring(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Execute = (BOOL)lua_toboolean(l, 3); IDE_CreateWindow(WindowType, Text, Execute); return 0; } int luax_IDE_OpenFile(lua_State *l) { BOOL retValue; int WindowType; char* Filename; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Filename = (char*)lua_tostring(l, 2); retValue = IDE_OpenFile(WindowType, Filename); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SaveFile(lua_State *l) { BOOL retValue; retValue = IDE_SaveFile(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_Filename(lua_State *l) { char* retValue; retValue = IDE_Filename(); lua_pushstring(l, retValue); return 1; } int luax_IDE_CloseFile(lua_State *l) { IDE_CloseFile(); return 0; } int luax_IDE_SetReadOnly(lua_State *l) { BOOL ReadOnly; if (!lua_isboolean(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ReadOnly = (BOOL)lua_toboolean(l, 1); IDE_SetReadOnly(ReadOnly); return 0; } int luax_IDE_GetReadOnly(lua_State *l) { BOOL retValue; retValue = IDE_GetReadOnly(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_ExecuteSQLReport(lua_State *l) { BOOL retValue; char* SQL; char* Title; BOOL Updateable; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } SQL = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Title = (char*)lua_tostring(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Updateable = (BOOL)lua_toboolean(l, 3); retValue = IDE_ExecuteSQLReport(SQL, Title, Updateable); lua_pushboolean(l, retValue); return 1; } int luax_IDE_ReloadFile(lua_State *l) { BOOL retValue; retValue = IDE_ReloadFile(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetFilename(lua_State *l) { char* Filename; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Filename = (char*)lua_tostring(l, 1); IDE_SetFilename(Filename); return 0; } int luax_IDE_GetText(lua_State *l) { char* retValue; retValue = IDE_GetText(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetSelectedText(lua_State *l) { char* retValue; retValue = IDE_GetSelectedText(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetCursorWord(lua_State *l) { char* retValue; retValue = IDE_GetCursorWord(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetEditorHandle(lua_State *l) { int retValue; retValue = IDE_GetEditorHandle(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_SetText(lua_State *l) { BOOL retValue; char* Text; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Text = (char*)lua_tostring(l, 1); retValue = IDE_SetText(Text); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetStatusMessage(lua_State *l) { BOOL retValue; char* Text; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Text = (char*)lua_tostring(l, 1); retValue = IDE_SetStatusMessage(Text); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetErrorPosition(lua_State *l) { BOOL retValue; int Line; int Col; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Line = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Col = (int)lua_tointeger(l, 2); retValue = IDE_SetErrorPosition(Line, Col); lua_pushboolean(l, retValue); return 1; } int luax_IDE_ClearErrorPositions(lua_State *l) { IDE_ClearErrorPositions(); return 0; } int luax_IDE_GetCursorWordPosition(lua_State *l) { int retValue; retValue = IDE_GetCursorWordPosition(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_Perform(lua_State *l) { BOOL retValue; int Param; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Param = (int)lua_tointeger(l, 1); retValue = IDE_Perform(Param); lua_pushboolean(l, retValue); return 1; } int luax_SQL_Execute(lua_State *l) { int retValue; char* SQL; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } SQL = (char*)lua_tostring(l, 1); retValue = SQL_Execute(SQL); lua_pushinteger(l, retValue); return 1; } int luax_SQL_FieldCount(lua_State *l) { int retValue; retValue = SQL_FieldCount(); lua_pushinteger(l, retValue); return 1; } int luax_SQL_Eof(lua_State *l) { BOOL retValue; retValue = SQL_Eof(); lua_pushboolean(l, retValue); return 1; } int luax_SQL_Next(lua_State *l) { int retValue; retValue = SQL_Next(); lua_pushinteger(l, retValue); return 1; } int luax_SQL_Field(lua_State *l) { char* retValue; int Field; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Field = (int)lua_tointeger(l, 1); retValue = SQL_Field(Field); lua_pushstring(l, retValue); return 1; } int luax_SQL_FieldName(lua_State *l) { char* retValue; int Field; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Field = (int)lua_tointeger(l, 1); retValue = SQL_FieldName(Field); lua_pushstring(l, retValue); return 1; } int luax_SQL_FieldIndex(lua_State *l) { int retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = SQL_FieldIndex(Name); lua_pushinteger(l, retValue); return 1; } int luax_SQL_FieldType(lua_State *l) { int retValue; int Field; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Field = (int)lua_tointeger(l, 1); retValue = SQL_FieldType(Field); lua_pushinteger(l, retValue); return 1; } int luax_SQL_ErrorMessage(lua_State *l) { char* retValue; retValue = SQL_ErrorMessage(); lua_pushstring(l, retValue); return 1; } int luax_SQL_UsePlugInSession(lua_State *l) { BOOL retValue; int PlugInID; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); retValue = SQL_UsePlugInSession(PlugInID); lua_pushboolean(l, retValue); return 1; } int luax_SQL_UseDefaultSession(lua_State *l) { int PlugInID; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); SQL_UseDefaultSession(PlugInID); return 0; } int luax_SQL_CheckConnection(lua_State *l) { BOOL retValue; retValue = SQL_CheckConnection(); lua_pushboolean(l, retValue); return 1; } int luax_SQL_GetDBMSGetOutput(lua_State *l) { char* retValue; retValue = SQL_GetDBMSGetOutput(); lua_pushstring(l, retValue); return 1; } int luax_SQL_SetVariable(lua_State *l) { char* Name; char* Value; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Value = (char*)lua_tostring(l, 2); SQL_SetVariable(Name, Value); return 0; } int luax_SQL_GetVariable(lua_State *l) { char* retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = SQL_GetVariable(Name); lua_pushstring(l, retValue); return 1; } int luax_SQL_ClearVariables(lua_State *l) { SQL_ClearVariables(); return 0; } int luax_IDE_GetCustomKeywords(lua_State *l) { char* retValue; retValue = IDE_GetCustomKeywords(); lua_pushstring(l, retValue); return 1; } int luax_IDE_SetCustomKeywords(lua_State *l) { char* Keywords; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Keywords = (char*)lua_tostring(l, 1); IDE_SetCustomKeywords(Keywords); return 0; } int luax_IDE_SetKeywords(lua_State *l) { int ID; int Style; char* Keywords; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Style = (int)lua_tointeger(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Keywords = (char*)lua_tostring(l, 3); IDE_SetKeywords(ID, Style, Keywords); return 0; } int luax_IDE_ActivateKeywords(lua_State *l) { IDE_ActivateKeywords(); return 0; } int luax_IDE_RefreshMenus(lua_State *l) { int ID; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); IDE_RefreshMenus(ID); return 0; } int luax_IDE_SetMenuName(lua_State *l) { int ID; int Index; char* Name; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); IDE_SetMenuName(ID, Index, Name); return 0; } int luax_IDE_SetMenuCheck(lua_State *l) { int ID; int Index; BOOL Enabled; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Enabled = (BOOL)lua_toboolean(l, 3); IDE_SetMenuCheck(ID, Index, Enabled); return 0; } int luax_IDE_SetMenuVisible(lua_State *l) { int ID; int Index; BOOL Enabled; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Enabled = (BOOL)lua_toboolean(l, 3); IDE_SetMenuVisible(ID, Index, Enabled); return 0; } int luax_IDE_GetMenulayout(lua_State *l) { char* retValue; retValue = IDE_GetMenulayout(); lua_pushstring(l, retValue); return 1; } int luax_IDE_CreatePopupItem(lua_State *l) { void* retValue; int ID; int Index; char* Name; char* ObjectType; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 4); retValue = IDE_CreatePopupItem(ID, Index, Name, ObjectType); // lua_pushinteger(l,retValue); lua_pushinteger(l, (int)retValue); return 1; } int luax_IDE_SetConnection(lua_State *l) { BOOL retValue; char* Username; char* Password; char* Database; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Username = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Password = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Database = (char*)lua_tostring(l, 3); retValue = IDE_SetConnection(Username, Password, Database); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetObjectInfo(lua_State *l) { // int retValue; // char* AnObject; // char** ObjectType; // char** ObjectOwner; // char** ObjectName; // char** SubObject; // if (!lua_isstring(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // AnObject = (char*)lua_tostring(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectType = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectOwner = (char**)lua_topointer(l, 3); // if (!lua_isnumber(l, 4)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectName = (char**)lua_topointer(l, 4); // if (!lua_isnumber(l, 5)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // SubObject = (char**)lua_topointer(l, 5); // retValue = IDE_GetObjectInfo(AnObject, ObjectType, ObjectOwner, ObjectName, // SubObject); // lua_pushinteger(l, retValue); // return 1; int retValue; char *AnObject; char* ObjectType; char* ObjectOwner; char* ObjectName; char* SubObject; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } AnObject = (char*)lua_tostring(l, 1); retValue = IDE_GetObjectInfo(AnObject, &ObjectType, &ObjectOwner, &ObjectName, &SubObject); lua_pushinteger(l, retValue); lua_pushstring(l, ObjectType); lua_pushstring(l, ObjectOwner); lua_pushstring(l, ObjectName); lua_pushstring(l, SubObject); return 5; } int luax_IDE_GetBrowserItems(lua_State *l) { char* retValue; char* Node; BOOL GetItems; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Node = (char*)lua_tostring(l, 1); if (!lua_isboolean(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } GetItems = (BOOL)lua_toboolean(l, 2); retValue = IDE_GetBrowserItems(Node, GetItems); lua_pushstring(l, retValue); return 1; } int luax_IDE_RefreshBrowser(lua_State *l) { char* Node; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Node = (char*)lua_tostring(l, 1); IDE_RefreshBrowser(Node); return 0; } int luax_IDE_GetPopupObject(lua_State *l) { // int retValue; // char** ObjectType; // char** ObjectOwner; // char** ObjectName; // char** SubObject; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectType = (char**)lua_topointer(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectOwner = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectName = (char**)lua_topointer(l, 3); // if (!lua_isnumber(l, 4)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // SubObject = (char**)lua_topointer(l, 4); // retValue = IDE_GetPopupObject(ObjectType, ObjectOwner, ObjectName, // SubObject); // lua_pushinteger(l, retValue); // return 1; int retValue; char* ObjectType; char* ObjectOwner; char* ObjectName; char* SubObject; retValue = IDE_GetPopupObject(&ObjectType, &ObjectOwner, &ObjectName, &SubObject); lua_pushstring(l, ObjectType); lua_pushstring(l, ObjectOwner); lua_pushstring(l, ObjectName); lua_pushstring(l, SubObject); lua_pushinteger(l, retValue); return 5; } int luax_IDE_GetPopupBrowserRoot(lua_State *l) { char* retValue; retValue = IDE_GetPopupBrowserRoot(); lua_pushstring(l, retValue); return 1; } int luax_IDE_RefreshObject(lua_State *l) { char* ObjectType; char* ObjectOwner; char* ObjectName; int Action; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectOwner = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectName = (char*)lua_tostring(l, 3); if (!lua_isnumber(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Action = (int)lua_tointeger(l, 4); IDE_RefreshObject(ObjectType, ObjectOwner, ObjectName, Action); return 0; } int luax_IDE_FirstSelectedObject(lua_State *l) { BOOL retValue; char* ObjectType; char* ObjectOwner; char* ObjectName; char* SubObject; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectOwner = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectName = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } SubObject = (char*)lua_tostring(l, 4); retValue = IDE_FirstSelectedObject(ObjectType, ObjectOwner, ObjectName, SubObject); lua_pushboolean(l, retValue); return 1; } int luax_IDE_NextSelectedObject(lua_State *l) { BOOL retValue; char* ObjectType; char* ObjectOwner; char* ObjectName; char* SubObject; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectOwner = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectName = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } SubObject = (char*)lua_tostring(l, 4); retValue = IDE_NextSelectedObject(ObjectType, ObjectOwner, ObjectName, SubObject); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetObjectSource(lua_State *l) { char* retValue; char* ObjectType; char* ObjectOwner; char* ObjectName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectOwner = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectName = (char*)lua_tostring(l, 3); retValue = IDE_GetObjectSource(ObjectType, ObjectOwner, ObjectName); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetWindowCount(lua_State *l) { int retValue; retValue = IDE_GetWindowCount(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_SelectWindow(lua_State *l) { BOOL retValue; int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); retValue = IDE_SelectWindow(Index); lua_pushboolean(l, retValue); return 1; } int luax_IDE_ActivateWindow(lua_State *l) { BOOL retValue; int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); retValue = IDE_ActivateWindow(Index); lua_pushboolean(l, retValue); return 1; } int luax_IDE_WindowIsModified(lua_State *l) { BOOL retValue; retValue = IDE_WindowIsModified(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_WindowIsRunning(lua_State *l) { BOOL retValue; retValue = IDE_WindowIsRunning(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SplashCreate(lua_State *l) { int ProgressMax; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ProgressMax = (int)lua_tointeger(l, 1); IDE_SplashCreate(ProgressMax); return 0; } int luax_IDE_SplashHide(lua_State *l) { IDE_SplashHide(); return 0; } int luax_IDE_SplashWrite(lua_State *l) { char* s; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } s = (char*)lua_tostring(l, 1); IDE_SplashWrite(s); return 0; } int luax_IDE_SplashWriteLn(lua_State *l) { char* s; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } s = (char*)lua_tostring(l, 1); IDE_SplashWriteLn(s); return 0; } int luax_IDE_SplashProgress(lua_State *l) { int Progress; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Progress = (int)lua_tointeger(l, 1); IDE_SplashProgress(Progress); return 0; } int luax_IDE_TemplatePath(lua_State *l) { char* retValue; retValue = IDE_TemplatePath(); lua_pushstring(l, retValue); return 1; } int luax_IDE_ExecuteTemplate(lua_State *l) { BOOL retValue; char* Template; BOOL NewWindow; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Template = (char*)lua_tostring(l, 1); if (!lua_isboolean(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } NewWindow = (BOOL)lua_toboolean(l, 2); retValue = IDE_ExecuteTemplate(Template, NewWindow); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetConnectAs(lua_State *l) { char *retValue; retValue = IDE_GetConnectAs(); lua_pushstring(l, retValue); return 1; } int luax_IDE_SetConnectionAs(lua_State *l) { BOOL retValue; char* Username; char* Password; char* Database; char* ConnectAs; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Username = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Password = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Database = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ConnectAs = (char*)lua_tostring(l, 4); retValue = IDE_SetConnectionAs(Username, Password, Database, ConnectAs); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetFileOpenMenu(lua_State *l) { // char* retValue; // int MenuIndex; // int* WindowType; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // MenuIndex = (int)lua_tointeger(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // WindowType = (int*)lua_topointer(l, 2); // retValue = IDE_GetFileOpenMenu(MenuIndex, WindowType); // lua_pushstring(l, retValue); // return 1; char* retValue; int MenuIndex; int WindowType; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } MenuIndex = (int)lua_tointeger(l, 1); retValue = IDE_GetFileOpenMenu(MenuIndex, &WindowType); lua_pushstring(l, retValue); lua_pushinteger(l, WindowType); return 2; } int luax_IDE_CanSaveWindow(lua_State *l) { BOOL retValue; retValue = IDE_CanSaveWindow(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_OpenFileExternal(lua_State *l) { int WindowType; char* Data; char* FileSystem; char* Tag; char* Filename; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Data = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } FileSystem = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Tag = (char*)lua_tostring(l, 4); if (!lua_isstring(l, 5)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Filename = (char*)lua_tostring(l, 5); IDE_OpenFileExternal(WindowType, Data, FileSystem, Tag, Filename); return 0; } int luax_IDE_GetFileTypes(lua_State *l) { char* retValue; int WindowType; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); retValue = IDE_GetFileTypes(WindowType); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetDefaultExtension(lua_State *l) { char* retValue; int WindowType; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); retValue = IDE_GetDefaultExtension(WindowType); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetFiledata(lua_State *l) { char* retValue; retValue = IDE_GetFiledata(); lua_pushstring(l, retValue); return 1; } int luax_IDE_FileSaved(lua_State *l) { char* FileSystem; char* FileTag; char* Filename; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } FileSystem = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } FileTag = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Filename = (char*)lua_tostring(l, 3); IDE_FileSaved(FileSystem, FileTag, Filename); return 0; } int luax_IDE_ShowHTML(lua_State *l) { BOOL retValue; char* Url; char* Hash; char* Title; char* ID; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Url = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Hash = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Title = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (char*)lua_tostring(l, 4); retValue = IDE_ShowHTML(Url, Hash, Title, ID); lua_pushboolean(l, retValue); return 1; } int luax_IDE_RefreshHTML(lua_State *l) { BOOL retValue; char* Url; char* ID; BOOL BringToFront; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Url = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (char*)lua_tostring(l, 2); if (!lua_isboolean(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } BringToFront = (BOOL)lua_toboolean(l, 3); retValue = IDE_RefreshHTML(Url, ID, BringToFront); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetProcEditExtension(lua_State *l) { char* retValue; char* oType; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } oType = (char*)lua_tostring(l, 1); retValue = IDE_GetProcEditExtension(oType); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetWindowObject(lua_State *l) { // BOOL retValue; // char** ObjectType; // char** ObjectOwner; // char** ObjectName; // char** SubObject; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectType = (char**)lua_topointer(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectOwner = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // ObjectName = (char**)lua_topointer(l, 3); // if (!lua_isnumber(l, 4)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // SubObject = (char**)lua_topointer(l, 4); // retValue = IDE_GetWindowObject(ObjectType, ObjectOwner, ObjectName, // SubObject); // lua_pushboolean(l, retValue); // return 1; BOOL retValue; char* ObjectType; char* ObjectOwner; char* ObjectName; char* SubObject; retValue = IDE_GetWindowObject(&ObjectType, &ObjectOwner, &ObjectName, &SubObject); lua_pushboolean(l, retValue); lua_pushstring(l, ObjectType); lua_pushstring(l, ObjectOwner); lua_pushstring(l, ObjectName); lua_pushstring(l, SubObject); return 5; } int luax_IDE_FirstSelectedFile(lua_State *l) { char* retValue; BOOL Files; BOOL Directories; if (!lua_isboolean(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Files = (BOOL)lua_toboolean(l, 1); if (!lua_isboolean(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Directories = (BOOL)lua_toboolean(l, 2); retValue = IDE_FirstSelectedFile(Files, Directories); lua_pushstring(l, retValue); return 1; } int luax_IDE_NextSelectedFile(lua_State *l) { char* retValue; retValue = IDE_NextSelectedFile(); lua_pushstring(l, retValue); return 1; } int luax_IDE_RefreshFileBrowser(lua_State *l) { IDE_RefreshFileBrowser(); return 0; } int luax_IDE_KeyPress(lua_State *l) { int Key; int Shift; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Key = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Shift = (int)lua_tointeger(l, 2); IDE_KeyPress(Key, Shift); return 0; } int luax_IDE_GetMenuItem(lua_State *l) { int retValue; char* MenuName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } MenuName = (char*)lua_tostring(l, 1); retValue = IDE_GetMenuItem(MenuName); lua_pushinteger(l, retValue); return 1; } int luax_IDE_SelectMenu(lua_State *l) { BOOL retValue; int MenuItem; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } MenuItem = (int)lua_tointeger(l, 1); retValue = IDE_SelectMenu(MenuItem); lua_pushboolean(l, retValue); return 1; } int luax_IDE_TranslationFile(lua_State *l) { char* retValue; retValue = IDE_TranslationFile(); lua_pushstring(l, retValue); return 1; } int luax_IDE_TranslationLanguage(lua_State *l) { char* retValue; retValue = IDE_TranslationLanguage(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetTranslatedMenuLayout(lua_State *l) { char* retValue; retValue = IDE_GetTranslatedMenuLayout(); lua_pushstring(l, retValue); return 1; } int luax_IDE_MainFont(lua_State *l) { char* retValue; retValue = IDE_MainFont(); lua_pushstring(l, retValue); return 1; } int luax_IDE_TranslateItems(lua_State *l) { char* retValue; char* Group; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Group = (char*)lua_tostring(l, 1); retValue = IDE_TranslateItems(Group); lua_pushstring(l, retValue); return 1; } int luax_IDE_TranslateString(lua_State *l) { char* retValue; char* ID; char* Default; char Param1; char Param2; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Default = (char*)lua_tostring(l, 2); if (!lua_isnumber(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Param1 = (char)lua_tointeger(l, 3); if (!lua_isnumber(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Param2 = (char)lua_tointeger(l, 4); retValue = IDE_TranslateString(ID, Default, Param1, Param2); lua_pushstring(l, retValue); return 1; } int luax_IDE_SaveRecoveryFiles(lua_State *l) { BOOL retValue; retValue = IDE_SaveRecoveryFiles(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetCursorX(lua_State *l) { int retValue; retValue = IDE_GetCursorX(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetCursorY(lua_State *l) { int retValue; retValue = IDE_GetCursorY(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_SetCursor(lua_State *l) { int X; int Y; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } X = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Y = (int)lua_tointeger(l, 2); IDE_SetCursor(X, Y); return 0; } int luax_IDE_SetBookmark(lua_State *l) { int retValue; int Index; int X; int Y; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } X = (int)lua_tointeger(l, 2); if (!lua_isnumber(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Y = (int)lua_tointeger(l, 3); retValue = IDE_SetBookmark(Index, X, Y); lua_pushinteger(l, retValue); return 1; } int luax_IDE_ClearBookmark(lua_State *l) { int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); IDE_ClearBookmark(Index); return 0; } int luax_IDE_GotoBookmark(lua_State *l) { int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); IDE_GotoBookmark(Index); return 0; } int luax_IDE_GetBookmark(lua_State *l) { BOOL retValue; int Index; int X; int Y; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } X = (int)lua_tointeger(l, 2); if (!lua_isnumber(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Y = (int)lua_tointeger(l, 3); retValue = IDE_GetBookmark(Index, X, Y); lua_pushboolean(l, retValue); return 1; } int luax_IDE_TabInfo(lua_State *l) { char* retValue; int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); retValue = IDE_TabInfo(Index); lua_pushstring(l, retValue); return 1; } int luax_IDE_TabIndex(lua_State *l) { int retValue; int Index; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); retValue = IDE_TabIndex(Index); lua_pushinteger(l, retValue); return 1; } int luax_IDE_CreateToolButton(lua_State *l) { int ID; int Index; char* Name; char* BitmapFile; int BitmapHandle; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ID = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } BitmapFile = (char*)lua_tostring(l, 4); if (!lua_isnumber(l, 5)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } BitmapHandle = (int)lua_tointeger(l, 5); IDE_CreateToolButton(ID, Index, Name, BitmapFile, BitmapHandle); return 0; } int luax_IDE_WindowHasEditor(lua_State *l) { BOOL retValue; BOOL CodeEditor; if (!lua_isboolean(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } CodeEditor = (BOOL)lua_toboolean(l, 1); retValue = IDE_WindowHasEditor(CodeEditor); lua_pushboolean(l, retValue); return 1; } int luax_IDE_BeautifierOptions(lua_State *l) { int retValue; retValue = IDE_BeautifierOptions(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_BeautifyWindow(lua_State *l) { BOOL retValue; retValue = IDE_BeautifyWindow(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_BeautifyText(lua_State *l) { char* retValue; char* S; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } S = (char*)lua_tostring(l, 1); retValue = IDE_BeautifyText(S); lua_pushstring(l, retValue); return 1; } int luax_IDE_ObjectAction(lua_State *l) { BOOL retValue; char* Action; char* ObjectType; char* ObjectOwner; char* ObjectName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Action = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectType = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectOwner = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ObjectName = (char*)lua_tostring(l, 4); retValue = IDE_ObjectAction(Action, ObjectType, ObjectOwner, ObjectName); lua_pushboolean(l, retValue); return 1; } int luax_IDE_ShowDialog(lua_State *l) { BOOL retValue; char* Dialog; char* Param; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Dialog = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Param = (char*)lua_tostring(l, 2); retValue = IDE_ShowDialog(Dialog, Param); lua_pushboolean(l, retValue); return 1; } int luax_IDE_DebugLog(lua_State *l) { char* Msg; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Msg = (char*)lua_tostring(l, 1); IDE_DebugLog(Msg); return 0; } int luax_IDE_GetParamString(lua_State *l) { char* retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = IDE_GetParamString(Name); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetParamBool(lua_State *l) { BOOL retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = IDE_GetParamBool(Name); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetBrowserFilter(lua_State *l) { // int Index; // char** Name; // char** WhereClause; // char** OrderByClause; // char** User; // BOOL Active; // if (!lua_isnumber(l, 1)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Index = (int)lua_tointeger(l, 1); // if (!lua_isnumber(l, 2)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Name = (char**)lua_topointer(l, 2); // if (!lua_isnumber(l, 3)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // WhereClause = (char**)lua_topointer(l, 3); // if (!lua_isnumber(l, 4)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // OrderByClause = (char**)lua_topointer(l, 4); // if (!lua_isnumber(l, 5)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // User = (char**)lua_topointer(l, 5); // if (!lua_isboolean(l, 6)) { // lua_pushstring(l, "incorrect argument"); // lua_error(l); // } // Active = (BOOL)lua_toboolean(l, 6); // IDE_GetBrowserFilter(Index, Name, WhereClause, OrderByClause, User, Active); // return 0; int Index; char* Name; char* WhereClause; char* OrderByClause; char* User; BOOL Active; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Index = (int)lua_tointeger(l, 1); if (!lua_isboolean(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Active = (BOOL)lua_toboolean(l, 2); IDE_GetBrowserFilter(Index, &Name, &WhereClause, &OrderByClause, &User, Active); lua_pushstring(l, Name); lua_pushstring(l, WhereClause); lua_pushstring(l, OrderByClause); lua_pushstring(l, User); return 4; } int luax_IDE_CommandFeedback(lua_State *l) { int FeedbackHandle; char* S; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } FeedbackHandle = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } S = (char*)lua_tostring(l, 2); IDE_CommandFeedback(FeedbackHandle, S); return 0; } int luax_IDE_ResultGridRowCount(lua_State *l) { int retValue; retValue = IDE_ResultGridRowCount(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_ResultGridColCount(lua_State *l) { int retValue; retValue = IDE_ResultGridColCount(); lua_pushinteger(l, retValue); return 1; } int luax_IDE_ResultGridCell(lua_State *l) { char* retValue; int Col; int Row; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Col = (int)lua_tointeger(l, 1); if (!lua_isnumber(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Row = (int)lua_tointeger(l, 2); retValue = IDE_ResultGridCell(Col, Row); lua_pushstring(l, retValue); return 1; } int luax_IDE_Authorized(lua_State *l) { BOOL retValue; char* Category; char* Name; char* SubName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Category = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } SubName = (char*)lua_tostring(l, 3); retValue = IDE_Authorized(Category, Name, SubName); lua_pushboolean(l, retValue); return 1; } int luax_IDE_WindowAllowed(lua_State *l) { BOOL retValue; int WindowType; BOOL ShowErrorMessage; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } WindowType = (int)lua_tointeger(l, 1); if (!lua_isboolean(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ShowErrorMessage = (BOOL)lua_toboolean(l, 2); retValue = IDE_WindowAllowed(WindowType, ShowErrorMessage); lua_pushboolean(l, retValue); return 1; } int luax_IDE_Authorization(lua_State *l) { BOOL retValue; retValue = IDE_Authorization(); lua_pushboolean(l, retValue); return 1; } int luax_IDE_AuthorizationItems(lua_State *l) { char* retValue; char* Category; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Category = (char*)lua_tostring(l, 1); retValue = IDE_AuthorizationItems(Category); lua_pushstring(l, retValue); return 1; } int luax_IDE_AddAuthorizationItem(lua_State *l) { int PlugInID; char* Name; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 2); IDE_AddAuthorizationItem(PlugInID, Name); return 0; } int luax_IDE_GetPersonalPrefSets(lua_State *l) { char* retValue; retValue = IDE_GetPersonalPrefSets(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetDefaultPrefSets(lua_State *l) { char* retValue; retValue = IDE_GetDefaultPrefSets(); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetPrefAsString(lua_State *l) { char* retValue; int PlugInID; char* PrefSet; char* Name; char* Default; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Default = (char*)lua_tostring(l, 4); retValue = IDE_GetPrefAsString(PlugInID, PrefSet, Name, Default); lua_pushstring(l, retValue); return 1; } int luax_IDE_GetPrefAsInteger(lua_State *l) { int retValue; int PlugInID; char* PrefSet; char* Name; BOOL Default; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isboolean(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Default = (BOOL)lua_toboolean(l, 4); retValue = IDE_GetPrefAsInteger(PlugInID, PrefSet, Name, Default); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetPrefAsBool(lua_State *l) { BOOL retValue; int PlugInID; char* PrefSet; char* Name; BOOL Default; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isboolean(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Default = (BOOL)lua_toboolean(l, 4); retValue = IDE_GetPrefAsBool(PlugInID, PrefSet, Name, Default); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetPrefAsString(lua_State *l) { BOOL retValue; int PlugInID; char* PrefSet; char* Name; char* Value; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isstring(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Value = (char*)lua_tostring(l, 4); retValue = IDE_SetPrefAsString(PlugInID, PrefSet, Name, Value); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetPrefAsInteger(lua_State *l) { BOOL retValue; int PlugInID; char* PrefSet; char* Name; int Value; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isnumber(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Value = (int)lua_tointeger(l, 4); retValue = IDE_SetPrefAsInteger(PlugInID, PrefSet, Name, Value); lua_pushboolean(l, retValue); return 1; } int luax_IDE_SetPrefAsBool(lua_State *l) { BOOL retValue; int PlugInID; char* PrefSet; char* Name; BOOL Value; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PrefSet = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 3); if (!lua_isboolean(l, 4)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Value = (BOOL)lua_toboolean(l, 4); retValue = IDE_SetPrefAsBool(PlugInID, PrefSet, Name, Value); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetGeneralPref(lua_State *l) { char* retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = IDE_GetGeneralPref(Name); lua_pushstring(l, retValue); return 1; } int luax_IDE_PlugInSetting(lua_State *l) { BOOL retValue; int PlugInID; char* Setting; char* Value; if (!lua_isnumber(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PlugInID = (int)lua_tointeger(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Setting = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Value = (char*)lua_tostring(l, 3); retValue = IDE_PlugInSetting(PlugInID, Setting, Value); lua_pushboolean(l, retValue); return 1; } int luax_IDE_GetProcOverloadCount(lua_State *l) { int retValue; char* Owner; char* PackageName; char* ProcedureName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Owner = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PackageName = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ProcedureName = (char*)lua_tostring(l, 3); retValue = IDE_GetProcOverloadCount(Owner, PackageName, ProcedureName); lua_pushinteger(l, retValue); return 1; } int luax_IDE_SelectProcOverloading(lua_State *l) { int retValue; char* Owner; char* PackageName; char* ProcedureName; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Owner = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } PackageName = (char*)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } ProcedureName = (char*)lua_tostring(l, 3); retValue = IDE_SelectProcOverloading(Owner, PackageName, ProcedureName); lua_pushinteger(l, retValue); return 1; } int luax_IDE_GetSessionValue(lua_State *l) { char* retValue; char* Name; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Name = (char*)lua_tostring(l, 1); retValue = IDE_GetSessionValue(Name); lua_pushstring(l, retValue); return 1; } int luax_IDE_CheckDBVersion(lua_State *l) { BOOL retValue; char* Version; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } Version = (char*)lua_tostring(l, 1); retValue = IDE_CheckDBVersion(Version); lua_pushboolean(l, retValue); return 1; }
此处为主程序主动发起的转嫁调用。
// Part 2,Call back function to call Lua script char* IdentifyPlugIn(int ID) { char* retValue; FC_TRACE("IdentifyPlugIn"); CHECK_LUA; /* Save the plugin ID in dynamic library */ SavePluginID(ID); lua_getglobal(L, "IdentifyPlugIn"); lua_pushinteger(L, ID); lua_pcall(L, 1, 1, 0); retValue = (char *)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } char* CreateMenuItem(int Index) { char* retValue; FC_TRACE("CreateMenuItem"); CHECK_LUA; lua_getglobal(L, "CreateMenuItem"); lua_pushinteger(L, Index); lua_pcall(L, 1, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } void OnMenuClick(int Index) { FC_TRACE("OnMenuClick"); CHECK_LUA; lua_getglobal(L, "OnMenuClick"); lua_pushinteger(L, Index); lua_pcall(L, 1, 0, 0); } void OnCreate() { FC_TRACE("OnCreate"); CHECK_LUA; lua_getglobal(L, "OnCreate"); lua_pcall(L, 0, 0, 0); } void OnActivate() { FC_TRACE("OnActivate"); CHECK_LUA; lua_getglobal(L, "OnActivate"); lua_pcall(L, 0, 0, 0); } void OnDeactivate() { FC_TRACE("OnDeactivate"); CHECK_LUA; lua_getglobal(L, "OnDeactivate"); lua_pcall(L, 0, 0, 0); } void OnDestroy() { FC_TRACE("OnDestroy"); CHECK_LUA; lua_getglobal(L, "OnDestroy"); lua_pcall(L, 0, 0, 0); /* Clear Lua support */ CLEAR_LUA; } BOOL CanClose() { BOOL retValue; FC_TRACE("CanClose"); CHECK_LUA; lua_getglobal(L, "CanClose"); lua_pcall(L, 0, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } void AfterStart() { FC_TRACE("AfterStart"); CHECK_LUA; lua_getglobal(L, "AfterStart"); lua_pcall(L, 0, 0, 0); } void OnBrowserChange() { FC_TRACE("OnBrowserChange"); CHECK_LUA; lua_getglobal(L, "OnBrowserChange"); lua_pcall(L, 0, 0, 0); } void OnWindowChange() { CHECK_LUA; lua_getglobal(L, "OnWindowChange"); lua_pcall(L, 0, 0, 0); } void OnWindowCreate(int WindowType) { FC_TRACE("OnWindowCreate"); CHECK_LUA; lua_getglobal(L, "OnWindowCreate"); lua_pushinteger(L, WindowType); lua_pcall(L, 1, 0, 0); } void OnWindowCreated(int WindowType) { FC_TRACE("OnWindowCreated"); CHECK_LUA; lua_getglobal(L, "OnWindowCreated"); lua_pushinteger(L, WindowType); lua_pcall(L, 1, 0, 0); } int OnWindowClose(int WindowType, BOOL Changed) { int retValue; FC_TRACE("OnWindowClose"); CHECK_LUA; lua_getglobal(L, "OnWindowClose"); lua_pushinteger(L, WindowType); lua_pushinteger(L, Changed); lua_pcall(L, 2, 1, 0); retValue = lua_tointeger(L, -1); lua_pop(L, 1); return retValue; } BOOL BeforeExecuteWindowe(int WindowType) { BOOL retValue; FC_TRACE("BeforeExecuteWindowe"); CHECK_LUA; lua_getglobal(L, "BeforeExecuteWindowe"); lua_pushinteger(L, WindowType); lua_pcall(L, 1, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } void AfterExecuteWindow(int WindowType, int Result) { FC_TRACE("AfterExecuteWindow"); CHECK_LUA; lua_getglobal(L, "AfterExecuteWindow"); lua_pushinteger(L, WindowType); lua_pushinteger(L, Result); lua_pcall(L, 2, 0, 0); } void OnConnectionChange() { FC_TRACE("OnConnectionChange"); CHECK_LUA; lua_getglobal(L, "OnConnectionChange"); lua_pcall(L, 0, 0, 0); } void OnPopup(char* ObjectType, char* ObjectName) { FC_TRACE("OnPopup"); CHECK_LUA; lua_getglobal(L, "OnPopup"); lua_pushstring(L, ObjectType); lua_pushstring(L, ObjectName); lua_pcall(L, 2, 0, 0); } void OnMainMenu(char* MenuName) { FC_TRACE("OnMainMenu"); CHECK_LUA; lua_getglobal(L, "OnMainMenu"); lua_pushstring(L, MenuName); lua_pcall(L, 1, 0, 0); } BOOL OnTemplate(char* Filename, char** Data) { BOOL retValue; char b[1024]; memset(b, '\0', sizeof(b)); FC_TRACE("OnTemplate"); CHECK_LUA; lua_getglobal(L, "OnTemplate"); lua_pushstring(L, Filename); // lua_pushinteger(L,Data); /* Modify by hand if need to use this feture */ lua_pushstring(L, *Data); /* Call function and return multiple values */ lua_pcall(L, 2, 2, 0); retValue = lua_toboolean(L, -2); *Data = lua_tostring(L, -1); lua_pop(L, 2); return retValue; } void OnFileLoaded(int WindowType, int Mode) { FC_TRACE("OnFileLoaded"); CHECK_LUA; lua_getglobal(L, "OnFileLoaded"); lua_pushinteger(L, WindowType); lua_pushinteger(L, Mode); lua_pcall(L, 2, 0, 0); } void OnFileSaved(int WindowType, int Mode) { FC_TRACE("OnFileSaved"); CHECK_LUA; lua_getglobal(L, "OnFileSaved"); lua_pushinteger(L, WindowType); lua_pushinteger(L, Mode); lua_pcall(L, 2, 0, 0); } char* About() { char* retValue; FC_TRACE("About"); CHECK_LUA; lua_getglobal(L, "About"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } void Configure() { FC_TRACE("Configure"); CHECK_LUA; lua_getglobal(L, "Configure"); lua_pcall(L, 0, 0, 0); } void CommandLine(int FeedbackHandle, char* Command, char* Params) { FC_TRACE("CommandLine"); CHECK_LUA; lua_getglobal(L, "CommandLine"); lua_pushinteger(L, FeedbackHandle); lua_pushstring(L, Command); lua_pushstring(L, Params); lua_pcall(L, 3, 0, 0); } char* PlugInName() { char* retValue; FC_TRACE("PlugInName"); CHECK_LUA; lua_getglobal(L, "PlugInName"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } char* PlugInSubName() { char* retValue; FC_TRACE("PlugInSubName"); CHECK_LUA; lua_getglobal(L, "PlugInSubName"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } char* PlugInShortName() { char* retValue; FC_TRACE("PlugInShortName"); CHECK_LUA; lua_getglobal(L, "PlugInShortName"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } char* RegisterFileSystem() { char* retValue; FC_TRACE("RegisterFileSystem"); CHECK_LUA; lua_getglobal(L, "RegisterFileSystem"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } char* DirectFileLoad() { char* retValue; FC_TRACE("DirectFileLoad"); CHECK_LUA; lua_getglobal(L, "DirectFileLoad"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } BOOL DirectFileSave() { BOOL retValue; FC_TRACE("DirectFileSave"); CHECK_LUA; lua_getglobal(L, "DirectFileSave"); lua_pcall(L, 0, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } char* RegisterExport() { char* retValue; FC_TRACE("RegisterExport"); CHECK_LUA; lua_getglobal(L, "RegisterExport"); lua_pcall(L, 0, 1, 0); retValue = (char*)lua_tostring(L, -1); lua_pop(L, 1); return retValue; } BOOL ExportInit() { BOOL retValue; FC_TRACE("ExportInit"); CHECK_LUA; lua_getglobal(L, "ExportInit"); lua_pcall(L, 0, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } void ExportFinished() { CHECK_LUA; lua_getglobal(L, "ExportFinished"); lua_pcall(L, 0, 0, 0); } BOOL ExportPrepare() { BOOL retValue; FC_TRACE("ExportPrepare"); CHECK_LUA; lua_getglobal(L, "ExportPrepare"); lua_pcall(L, 0, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } BOOL ExportData(char* Value) { BOOL retValue; FC_TRACE("ExportData"); CHECK_LUA; lua_getglobal(L, "ExportData"); lua_pushstring(L, Value); lua_pcall(L, 1, 1, 0); retValue = lua_toboolean(L, -1); lua_pop(L, 1); return retValue; } /* Automatically generate code end. */
头文件的定义,包括事件函数、插件函数、回调函数、转嫁调用函数等声明。
#ifndef __PLUGIN_H__ #define __PLUGIN_H__ /* Commmon use of windows utilities */ #include <windows.h> /* Embeded language Lua header files */ #ifdef __cplusplus extern "C" { #endif #include "lua.h" #include "lualib.h" #include "lauxlib.h" #ifdef __cplusplus } #endif /*Include common header files*/ #include "common.h" /* Export to IDE function groups */ #ifdef __cplusplus extern "C" { #endif /* Plug-in primary functions */ __declspec(dllexport)char*IdentifyPlugIn(int ID); __declspec(dllexport)char*CreateMenuItem(int Index); __declspec(dllexport)void OnMenuClick(int Index); /* Plug-in event functions */ __declspec(dllexport)void OnCreate(); __declspec(dllexport)void OnActivate(); __declspec(dllexport)void OnDeactivate(); __declspec(dllexport)void OnDestroy(); __declspec(dllexport)BOOL CanClose(); __declspec(dllexport)void AfterStart(); __declspec(dllexport)void OnBrowserChange(); __declspec(dllexport)void OnWindowChange(); __declspec(dllexport)void OnWindowCreate(int WindowType); __declspec(dllexport)void OnWindowCreated(int WindowType); __declspec(dllexport)int OnWindowClose(int WindowType, BOOL Changed); __declspec(dllexport)BOOL BeforeExecuteWindowe(int WindowType); __declspec(dllexport)void AfterExecuteWindow(int WindowType, int Result); __declspec(dllexport)void OnConnectionChange(); __declspec(dllexport)void OnPopup(char*ObjectType, char*ObjectName); __declspec(dllexport)void OnMainMenu(char*MenuName); __declspec(dllexport)BOOL OnTemplate(char*Filename, char**Data); __declspec(dllexport)void OnFileLoaded(int WindowType, int Mode); __declspec(dllexport)void OnFileSaved(int WindowType, int Mode); __declspec(dllexport)char*About(); __declspec(dllexport)void Configure(); __declspec(dllexport)void CommandLine(int FeedbackHandle, char*Command, char*Params); /* Plug-in nameing functions */ __declspec(dllexport)char*PlugInName(); __declspec(dllexport)char*PlugInSubName(); __declspec(dllexport)char*PlugInShortName(); /* Plug-in external filesystem functions */ __declspec(dllexport)char*RegisterFileSystem(); __declspec(dllexport)char*DirectFileLoad(); __declspec(dllexport)BOOL DirectFileSave(); /* Plug-in export functions */ __declspec(dllexport)char*RegisterExport(); __declspec(dllexport)BOOL ExportInit(); __declspec(dllexport)void ExportFinished(); __declspec(dllexport)BOOL ExportPrepare(); __declspec(dllexport)BOOL ExportData(char*Value); /* Plug-in callback functions */ __declspec(dllexport)void RegisterCallback(int Index, void*Addr); #ifdef __cplusplus } #endif /* Tab type returned by IDE_TabInfo() */ #define PLSQL_TT_FUNCTION "Function" #define PLSQL_TT_PROCEDURE "Procedure" #define PLSQL_TT_TRIGGER "Trigger" #define PLSQL_TT_JAVA_SOURCE "Java source" #define PLSQL_TT_PACKAGE_SPEC "Package" #define PLSQL_TT_PACKAGE_BODY "Package body" #define PLSQL_TT_TYPE_SPEC "Type" #define PLSQL_TT_TYPE_BODY "Type body" /* window type */ #define PLSQL_WT_UNKNOWN 0 #define PLSQL_WT_SQL 1 #define PLSQL_WT_TEST 2 #define PLSQL_WT_PROCEDURE 3 #define PLSQL_WT_COMMAND 4 #define PLSQL_WT_PLAN 5 #define PLSQL_WT_REPORT 6 /* Cursor word position */ #define PLSQL_CWP_UNKNOWN 0 #define PLSQL_CWP_CURSOR_START_WORD 1 #define PLSQL_CWP_CURSOR_WORD 2 #define PLSQL_CWP_CURSOR_END_WORD 3 /* Perform */ #define PLSQL_PERFORM_EXECUTE 1 #define PLSQL_PERFORM_BREAK 2 #define PLSQL_PERFORM_KILL 3 #define PLSQL_PERFORM_COMMIT 4 #define PLSQL_PERFORM_ROLLBACK 5 #define PLSQL_PERFORM_PRINT 6 /* Keyword style */ #define PLSQL_KWS_CUSTOM 10 #define PLSQL_KWS_KEYWORDS 11 #define PLSQL_KWS_COMMENT 12 #define PLSQL_KWS_STRINGS 13 #define PLSQL_KWS_NUMBERS 14 #define PLSQL_KWS_SYMBOLS 15 /* Popup */ #define PLSQL_POPUP_PROGRAMWINDOW "PROGRAMWINDOW" #define PLSQL_POPUP_SQLWINDOW "SQLWINDOW" #define PLSQL_POPUP_TESTWINDOW "TESTWINDOW" #define PLSQL_POPUP_COMMANDWINDOW "COMMANDWINDOW" /* Refresh object */ #define PLSQL_REFRESH_OBJECT_CREATED 1 #define PLSQL_REFRESH_OBJECT_MODIFIED 2 #define PLSQL_REFRESH_OBJECT_DELETED 3 /* Key simulation */ #define PLSQL_KP_SHIFT 1 #define PLSQL_KP_ALT 2 #define PLSQL_KP_CTRL 3 /* Beautifier options */ #define PLSQL_BO_AfterCreating 1 #define PLSQL_BO_AfterLoading 2 #define PLSQL_BO_BeforeCompiling 4 #define PLSQL_BO_BeforeSaving 8 /* SQL field type */ #define PLSQL_FT_Integer 3 #define PLSQL_FT_Float 4 #define PLSQL_FT_String 5 #define PLSQL_FT_Long 8 #define PLSQL_FT_Date 12 #define PLSQL_FT_LongRaw 24 /* Define error code */ #define ANYTHING_IS_OK 0 #define GENERAL_LUA_ERROR -1 #define REGISTER_ROUTINE_ERROR -11 /* Common definition */ #define LUA_MESSAGE_SIZE 1024 #define MAX_OBJECT_NAME_LEN 256 /* Lua c function pointer type */ typedef int(*lua_CF)(lua_State * l); /* Tools function declaration */ int RegisterRoutine(lua_State *l, const char *routine, lua_CF fp); lua_State *SetupLuaSupport(); void ClearLuaSupport(); static void Stack2Buff(lua_State *L, char *buff); /* Check the lua support was fixed */ #define CHECK_LUA SetupLuaSupport() #define CLEAR_LUA ClearLuaSupport() #ifdef _DEBUG #define FC_TRACE(fn) //MessageBox((HWND)GetDesktopWindow(), fn, "Function call trace...", MB_OK) #else #define FC_TRACE(fn) #endif //_DEBUG /* Function declare for lua "library" */ /* Part 1,manual created functions */ int luax_ShowMessage(lua_State *l); int luax_ShowMessageOption(lua_State *l); int luax_FetchData(lua_State *l); int luax_GetOpenFileName(lua_State *l); int luax_GetSaveFileName(lua_State *l); /* Part 2,auto created funcrions */ int luax_SYS_Version(lua_State *l); int luax_SYS_Registry(lua_State *l); int luax_SYS_RootDir(lua_State *l); int luax_SYS_OracleHome(lua_State *l); int luax_SYS_OCIDLL(lua_State *l); int luax_SYS_OCI8Mode(lua_State *l); int luax_SYS_XPStyle(lua_State *l); int luax_SYS_TNSNAMES(lua_State *l); int luax_SYS_DelphiVersion(lua_State *l); int luax_IDE_MenuState(lua_State *l); int luax_IDE_Connected(lua_State *l); int luax_IDE_GetConnectionInfo(lua_State *l); int luax_IDE_GetBrowserInfo(lua_State *l); int luax_IDE_GetWindowType(lua_State *l); int luax_IDE_GetAppHandle(lua_State *l); int luax_IDE_GetWindowHandle(lua_State *l); int luax_IDE_GetClientHandle(lua_State *l); int luax_IDE_GetChildHandle(lua_State *l); int luax_IDE_Refresh(lua_State *l); int luax_IDE_CreateWindow(lua_State *l); int luax_IDE_OpenFile(lua_State *l); int luax_IDE_SaveFile(lua_State *l); int luax_IDE_Filename(lua_State *l); int luax_IDE_CloseFile(lua_State *l); int luax_IDE_SetReadOnly(lua_State *l); int luax_IDE_GetReadOnly(lua_State *l); int luax_IDE_ExecuteSQLReport(lua_State *l); int luax_IDE_ReloadFile(lua_State *l); int luax_IDE_SetFilename(lua_State *l); int luax_IDE_GetText(lua_State *l); int luax_IDE_GetSelectedText(lua_State *l); int luax_IDE_GetCursorWord(lua_State *l); int luax_IDE_GetEditorHandle(lua_State *l); int luax_IDE_SetText(lua_State *l); int luax_IDE_SetStatusMessage(lua_State *l); int luax_IDE_SetErrorPosition(lua_State *l); int luax_IDE_ClearErrorPositions(lua_State *l); int luax_IDE_GetCursorWordPosition(lua_State *l); int luax_IDE_Perform(lua_State *l); int luax_SQL_Execute(lua_State *l); int luax_SQL_FieldCount(lua_State *l); int luax_SQL_Eof(lua_State *l); int luax_SQL_Next(lua_State *l); int luax_SQL_Field(lua_State *l); int luax_SQL_FieldName(lua_State *l); int luax_SQL_FieldIndex(lua_State *l); int luax_SQL_FieldType(lua_State *l); int luax_SQL_ErrorMessage(lua_State *l); int luax_SQL_UsePlugInSession(lua_State *l); int luax_SQL_UseDefaultSession(lua_State *l); int luax_SQL_CheckConnection(lua_State *l); int luax_SQL_GetDBMSGetOutput(lua_State *l); int luax_SQL_SetVariable(lua_State *l); int luax_SQL_GetVariable(lua_State *l); int luax_SQL_ClearVariables(lua_State *l); int luax_IDE_GetCustomKeywords(lua_State *l); int luax_IDE_SetCustomKeywords(lua_State *l); int luax_IDE_SetKeywords(lua_State *l); int luax_IDE_ActivateKeywords(lua_State *l); int luax_IDE_RefreshMenus(lua_State *l); int luax_IDE_SetMenuName(lua_State *l); int luax_IDE_SetMenuCheck(lua_State *l); int luax_IDE_SetMenuVisible(lua_State *l); int luax_IDE_GetMenulayout(lua_State *l); int luax_IDE_CreatePopupItem(lua_State *l); int luax_IDE_SetConnection(lua_State *l); int luax_IDE_GetObjectInfo(lua_State *l); int luax_IDE_GetBrowserItems(lua_State *l); int luax_IDE_RefreshBrowser(lua_State *l); int luax_IDE_GetPopupObject(lua_State *l); int luax_IDE_GetPopupBrowserRoot(lua_State *l); int luax_IDE_RefreshObject(lua_State *l); int luax_IDE_FirstSelectedObject(lua_State *l); int luax_IDE_NextSelectedObject(lua_State *l); int luax_IDE_GetObjectSource(lua_State *l); int luax_IDE_GetWindowCount(lua_State *l); int luax_IDE_SelectWindow(lua_State *l); int luax_IDE_ActivateWindow(lua_State *l); int luax_IDE_WindowIsModified(lua_State *l); int luax_IDE_WindowIsRunning(lua_State *l); int luax_IDE_SplashCreate(lua_State *l); int luax_IDE_SplashHide(lua_State *l); int luax_IDE_SplashWrite(lua_State *l); int luax_IDE_SplashWriteLn(lua_State *l); int luax_IDE_SplashProgress(lua_State *l); int luax_IDE_TemplatePath(lua_State *l); int luax_IDE_ExecuteTemplate(lua_State *l); int luax_IDE_GetConnectAs(lua_State *l); int luax_IDE_SetConnectionAs(lua_State *l); int luax_IDE_GetFileOpenMenu(lua_State *l); int luax_IDE_CanSaveWindow(lua_State *l); int luax_IDE_OpenFileExternal(lua_State *l); int luax_IDE_GetFileTypes(lua_State *l); int luax_IDE_GetDefaultExtension(lua_State *l); int luax_IDE_GetFiledata(lua_State *l); int luax_IDE_FileSaved(lua_State *l); int luax_IDE_ShowHTML(lua_State *l); int luax_IDE_RefreshHTML(lua_State *l); int luax_IDE_GetProcEditExtension(lua_State *l); int luax_IDE_GetWindowObject(lua_State *l); int luax_IDE_FirstSelectedFile(lua_State *l); int luax_IDE_NextSelectedFile(lua_State *l); int luax_IDE_RefreshFileBrowser(lua_State *l); int luax_IDE_KeyPress(lua_State *l); int luax_IDE_GetMenuItem(lua_State *l); int luax_IDE_SelectMenu(lua_State *l); int luax_IDE_TranslationFile(lua_State *l); int luax_IDE_TranslationLanguage(lua_State *l); int luax_IDE_GetTranslatedMenuLayout(lua_State *l); int luax_IDE_MainFont(lua_State *l); int luax_IDE_TranslateItems(lua_State *l); int luax_IDE_TranslateString(lua_State *l); int luax_IDE_SaveRecoveryFiles(lua_State *l); int luax_IDE_GetCursorX(lua_State *l); int luax_IDE_GetCursorY(lua_State *l); int luax_IDE_SetCursor(lua_State *l); int luax_IDE_SetBookmark(lua_State *l); int luax_IDE_ClearBookmark(lua_State *l); int luax_IDE_GotoBookmark(lua_State *l); int luax_IDE_GetBookmark(lua_State *l); int luax_IDE_TabInfo(lua_State *l); int luax_IDE_TabIndex(lua_State *l); int luax_IDE_CreateToolButton(lua_State *l); int luax_IDE_WindowHasEditor(lua_State *l); int luax_IDE_BeautifierOptions(lua_State *l); int luax_IDE_BeautifyWindow(lua_State *l); int luax_IDE_BeautifyText(lua_State *l); int luax_IDE_ObjectAction(lua_State *l); int luax_IDE_ShowDialog(lua_State *l); int luax_IDE_DebugLog(lua_State *l); int luax_IDE_GetParamString(lua_State *l); int luax_IDE_GetParamBool(lua_State *l); int luax_IDE_GetBrowserFilter(lua_State *l); int luax_IDE_CommandFeedback(lua_State *l); int luax_IDE_ResultGridRowCount(lua_State *l); int luax_IDE_ResultGridColCount(lua_State *l); int luax_IDE_ResultGridCell(lua_State *l); int luax_IDE_Authorized(lua_State *l); int luax_IDE_WindowAllowed(lua_State *l); int luax_IDE_Authorization(lua_State *l); int luax_IDE_AuthorizationItems(lua_State *l); int luax_IDE_AddAuthorizationItem(lua_State *l); int luax_IDE_GetPersonalPrefSets(lua_State *l); int luax_IDE_GetDefaultPrefSets(lua_State *l); int luax_IDE_GetPrefAsString(lua_State *l); int luax_IDE_GetPrefAsInteger(lua_State *l); int luax_IDE_GetPrefAsBool(lua_State *l); int luax_IDE_SetPrefAsString(lua_State *l); int luax_IDE_SetPrefAsInteger(lua_State *l); int luax_IDE_SetPrefAsBool(lua_State *l); int luax_IDE_GetGeneralPref(lua_State *l); int luax_IDE_PlugInSetting(lua_State *l); int luax_IDE_GetProcOverloadCount(lua_State *l); int luax_IDE_SelectProcOverloading(lua_State *l); int luax_IDE_GetSessionValue(lua_State *l); int luax_IDE_CheckDBVersion(lua_State *l); /****************************************************************************** / /*All IDE functions declare */ /* Delphi procedure IDE_RefreshBrowser(Node: PChar) Force a refresh to the Object Browser. If Node is empty, all items are refreshed. To refresh a specific item you can enter the name in the Node parameter. Note: Version 500 allows you to pass a * to refresh the current selected browser item. Note: Version 600 allows you to pass a ** to refresh to parent of the current browser item, and you can pass *** to refresh to root item. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_RefreshBrowser)(char *Node); /* Delphi function IDE_SetBookmark(Index, X, Y: Integer): Integer Create a bookmark at position X (character), Y (line). Index is the bookmark (0..9) you want to set. If you pass –1 as bookmark, the first free bookmark will be used. The returned value is the used bookmark. Normally, from within PL/SQL Developer. Bookmarks can only be used for windows with a gutter (Test window and Program editor), but the Plug-In interface allows you to use bookmarks for all windows. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_SetBookmark)(int Index, int X, int Y); /* Delphi procedure IDE_ClearBookmark(Index: Integer) Clears the specified bookmark $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_ClearBookmark)(int Index); /* Delphi procedure IDE_GotoBookmark(Index: Integer) Jumps to a bookmark $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_GotoBookmark)(int Index); /* Delphi function IDE_GetBookmark(Index: Integer; var X: Integer;var Y: Integer): Bool Get the cursor position for a specific bookmark $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_GetBookmark)(int Index, int X, int Y); /* Delphi function IDE_TabInfo(Index: Integer): PChar Returns the description tab page Index (zero based). The return value is empty if the tab page does not exist. This function allows you to determine which tab pages (if any) are available for the current window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TabInfo)(int Index); /* Delphi function IDE_TabIndex(Index: Integer): Integer This function allows you to read or set the active tab page. To set a specific page, pass a zero based value to the Index parameter. The return value is the actual selected page. To determine the active page (without setting it) pass a value of –1 to the Index parameter. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_TabIndex)(int Index); /* Delphi procedure IDE_CreateToolButton(ID, Index: Integer;Name: PChar; BitmapFile: PChar;BitmapHandle: Integer) This function allows you to add Toolbuttons to your Plug-In, similar to IDE_CreatePopupItem. The ID is the Plug-In ID and the index is the menu index. When a button is selected, OnMenuClick is called with the corresponding index. The Name will appear as hint for the button, and as name in the preferences dialog. The button can be enabled and disabled with IDE_MenuState. The image for the button can be set by passing a filename to a bmp file in the BitmapFile parameter, or as a handle to a bitmap in memory. The bmp image can have any number of colors, but should approximately be 20 x 20 pixels in size. The button will only be visible if it is selected in the Toolbar preference. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_CreateToolButton)(int ID, int Index, char *Name, char *BitmapFile, int BitmapHandle); /* Delphi procedure IDE_WindowHasEditor(CodeEditor: Bool) Returns true if the current Window has an Editor. If the CodeEditor parameter is true, it returns false for editors like the output editor. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_WindowHasEditor)(BOOL CodeEditor); /* Delphi function IDE_BeautifierOptions: Integer Returns the PL/SQL Beautifier options. The result is a value where the following values are or-ed together: 1 AfterCreating enabled 2 AfterLoading enabled 4 BeforeCompiling enabled 8 BeforeSaving enabled You can use this to determine if you need to call the beautifier. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_BeautifierOptions)(); /* Delphi function IDE_BeautifyWindow: Bool Calls the PL/SQL Beautifier for the current Window. The result indicates if the operations succeeded. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_BeautifyWindow)(); /* Delphi function IDE_BeautifyText(S: PChar): PChar Calls the PL/SQL Beautifier to beautify the text in the S parameter. The result is the beautified text or it is empty if the function failed $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_BeautifyText)(char *S); /* Delphi IDE_ObjectAction(Action, ObjectType, ObjectOwner, ObjectName: PChar): Bool This function allows you to do a specific action for the object specified. The following actions are available: VIEW, VIEWSPECANDBODY, EDIT, EDITSPECANDBODY, EDITDATA, QUERYDATA, TEST $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ObjectAction)(char *Action, char *ObjectType, char *ObjectOwner, char *ObjectName); /* Delphi function IDE_ShowDialog(Dialog, Param: PChar): Bool This allows you to start a specific PL/SQL Developer dialog. The following are supported: AUTHORIZATIONS PROJECTITEMS BREAKPOINTS PREFERENCES CONFIG PLUGINS CONFIG TOOLS CONFIG DOCUMENTS CONFIG REPORTS CONFIG MACROS CONFIG AUTOREFRESH The Param parameter is for future use. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ShowDialog)(char *Dialog, char *Param); /* Delphi function IDE_ExecuteTemplate(Template: PChar;NewWindow: Bool): Bool If you want to execute a template from within your PlugIn you can do so with this function. The NewWindow parameter indicates if a new window should be created or that the result of the template should be pasted at the current cursor position in the active window. The template parameter should contain the template name. If the template is located in one or more folders, the folder name(s) should be prefixed to the template name separated by a backslash. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ExecuteTemplate)(char *Template, BOOL NewWindow); /* Delphi function IDE_GetConnectAs: PChar Use this function to determine if the current connection has a specific ‘Connect As’. Possible return values are: '', 'SYSDBA' and 'SYSOPER' $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char*(*IDE_GetConnectAs)(); /* Delphi function IDE_SetConnectionAs(Username, Password, Database, ConnectAs: PChar): Bool Identical to IDE_SetConnection, but with an option to specify a ConnectAs parameter. You can pass 'SYSDBA' or 'SYSOPER', all other values will be handled as 'NORMAL'. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetConnectionAs)(char *Username, char *Password, char *Database, char *ConnectAs); /* Delphi function IDE_GetFileOpenMenu(MenuIndex: Integer;var WindowType: Integer): PChar If you want to create a new ‘File Open’ menu with the same items as the standard menu, you can use this function to determine the standard items. You can call this function in a loop while incrementing MenuIndex (starting with 0) until the return value is an empty string. The return values are the menu names in the File Open menu and the WindowType is the corresponding window type. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetFileOpenMenu)(int MenuIndex, int *WindowType); /* Delphi function IDE_CanSaveWindow: Bool Returns True if the active child window can be saved. (which are the SQL, Test, Program and Command windows). $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_CanSaveWindow)(); /* Delphi procedure IDE_OpenFileExternal(WindowType: Integer;Data, FileSystem, Tag, Filename: PChar) Creates a new Window (of type WindowType) for the specified (and registered) FileSystem, Tag and Filename. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_OpenFileExternal)(int WindowType, char *Data, char *FileSystem, char *Tag, char *Filename); /* Delphi function IDE_GetFileTypes(WindowType: Integer): PChar Returns the defined filetypes for a specific WindowType. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetFileTypes)(int WindowType); /* Delphi function IDE_GetDefaultExtension(WindowType: Integer): PChar Returns the default extension (without period) for a specific window type. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetDefaultExtension)(int WindowType); /* Delphi function IDE_GetFileData: PChar Returns the data of a window. You can use this function to get the data and save it. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetFiledata)(); /* Delphi procedure IDE_FileSaved(FileSystem, FileTag, Filename: PChar) You can call this function when a file is saved successfully. The filename will be set in the Window caption and the status will display that the file is ‘saved successfully’. FileSystem and FileTag can be nil. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_FileSaved)(char *FileSystem, char *FileTag, char *Filename); /* Delphi function IDE_ShowHTML(Url, Hash, Title, ID: PChar): Bool This function displays a html file in a child window. The url parameter identifies the file and the hash parameter allows you to jump to a specific location. The title parameter will be used as window title. You can refresh the contents of an already opened window by specifying an ID. If ID is not empty, and a window exists with the same ID, this will be used, otherwise a new window will be created. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ShowHTML)(char *Url, char *Hash, char *Title, char *ID); /* Delphi function IDE_ShowHTML(Url, ID: PChar; BringToFront: Bool): Bool Refresh the contents of a HTML Window. You can pass an url to refresh all windows that show a specific url, or you can pass an ID to refresh a specific Window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_RefreshHTML)(char *Url, char *ID, BOOL BringToFront); /* Delphi function IDE_GetProcEditExtension (oType: PChar): PChar Returns the define file extension of a specific object type. The oType parameter can hold one of the following valies: FUNCTION, PROCEDURE, TRIGGER, PACKAGE, PACKAGE BODY, PACKAGE SPEC AND BODY, TYPE, TYPE BODY, TYPE SPEC AND BODY, JAVA SOURCE $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetProcEditExtension)(char *oType); /* Delphi function IDE_GetWindowObject(var ObjectType, ObjectOwner, ObjectName, SubObject: PChar): Bool Get info about the object opened in a Window. This will only work for Program Windows. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_GetWindowObject)(char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject); /* Delphi function IDE_FirstSelectedFile(Files, Directories: Boolean): PChar;Returns the first selected item in the file browser. Use IDE_NextSelectedFile for multiple selected items. The Files and Directories parameters allow you to specify if you do or don’t want selected files and/or directories. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_FirstSelectedFile)(BOOL Files, BOOL Directories); /* Delphi function IDE_NextSelectedFile: PChar Returns the next selected item. See the previous function. Returns empty value when no more items. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_NextSelectedFile)(); /* Delphi procedure IDE_RefreshFileBrowser Forces the file browser to refresh the contents. Normally the browser will autodetect changes. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_RefreshFileBrowser)(); /* Delphi procedure IDE_KeyPress(Key, Shift: Integer) Simulates a key press. You can use this function to do the things you can also do with the keyboard. The Key parameter is the virtual key code of the key, and the Shift parameter holds the status of the Shift Ctrl and Alt keys. You can combine the following values: 1 = Shift 2 = Alt 3 = Ctrl $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_KeyPress)(int Key, int Shift); /* Delphi function IDE_GetMenuItem(MenuName: PChar): Integer This function will return an ‘index’ of a specific menu item. The MenuName parameter must specify the menu path separated by a slash, for example ‘edit / selection / uppercase’. The menu name is not case sensitive. If the function returns zero, the menu did not exist. You can use the return value with IDE_SelectMenu $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetMenuItem)(char *MenuName); /* Delphi function IDE_SelectMenu(MenuItem: Integer): Bool You can execute a menu item with this function. The MenuItem parameter has to be determined by the IDE_SelectMenu function. If this function returns false, the menu did not exist, or it was disabled. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SelectMenu)(int MenuItem); /* Delphi function IDE_TranslationFile: PChar Returns the currently used translation file. If the return value is empty, no translation is used. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TranslationFile)(); /* Delphi function IDE_TranslationLanguage: PChar Returns the language of the currently used translation file. If the return value is empty, no translation is used. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TranslationLanguage)(); /* Delphi function IDE_GetTranslatedMenuLayout: PChar Returns a list of all standard PL/SQL Developer menu items like IDE_GetMenuLayout, but this function will return the translated menus. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetTranslatedMenuLayout)(); /* Delphi function IDE_MainFont: PChar Return the PL/SQL Developer main font in the format: “Name”, size, color, charset, “style” $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_MainFont)(); /* Delphi procedure IDE_DebugLog(Msg: PChar) When debuggin is on, this function allows you to add messages in the debug.txt file generated. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_DebugLog)(char *Msg); /* Delphi function IDE_GetParamString(Name: PChar): PChar This function returns a command-line parameter, or a parameter specified in the params.ini file. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetParamString)(char *Name); /* Delphi function IDE_GetParamBool(Name: PChar): Bool This function returns a command-line parameter, or a parameter specified in the params.ini file. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_GetParamBool)(char *Name); /* Delphi procedure IDE_GetBrowserFilter(Index: Integer; var Name, WhereClause, OrderByClause, User: PChar; var Active: Bool) This function returns the defined browser filters. You can use this if the Plug-in has a similar requirement. Index = 0 and higher, and the returned values are empty if the filter does not exist. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_GetBrowserFilter)(int Index, char **Name, char **WhereClause, char **OrderByClause, char **User, BOOL Active); /* Delphi procedure IDE_CommandFeedback(FeedBackHandle: Integer; S: PChar) This function allows you to return feedback to the command window. The description S will be displayed in the window identified by the FeedbackHandle. See the CommandLine Plug-In function for details. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_CommandFeedback)(int FeedbackHandle, char *S); /* Delphi function IDE_ResultGridRowCount: Integer Returns the number of rows in the result grid of a SQL or Test Window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_ResultGridRowCount)(); /* Delphi function IDE_ResultGridColCount: Integer Returns the number of cols in the result grid of a SQL or Test Window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_ResultGridColCount)(); /* Delphi function IDE_ResultGridCell(Col, Row: Integer): PChar This function allows you to access the results of a query in a SQL or Test Window. Use the above two functions to determine the number of rows and cols. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_ResultGridCell)(int Col, int Row); /* Delphi procedure IDE_GetPopupObject(var ObjectType, ObjectOwner, ObjectName, SubObject: PChar) This function returns information about the item for which a popup menu (created with IDE_CreatePopupItem) was activated. If the item is a Browser folder, the name of the folder will be returned in ObjectName and ObjectType will return ‘FOLDER’ $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetPopupObject)(char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject); /* Delphi function IDE_GetPopupBrowserRoot: PChar This function returns the name of browser root item for which a popup menu (created with IDE_CreatePopupItem) was activated. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetPopupBrowserRoot)(); /* Delphi procedure IDE_RefreshObject(ObjectType, ObjectOwner, ObjectName: PChar; Action: Integer) If you modify database objects in your Plug-In and you want to update PL/SQL Developer to reflect these changes, you can do so by calling this function. You should pass the object type, owner, name and the action that you performed on the object. The action can be one of the following: 1 = Object created 2 = Object modified 3 = Object deleted PL/SQL Developer will update the browser and all windows that might use the object. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_RefreshObject)(char *ObjectType, char *ObjectOwner, char *ObjectName, int Action); /* Delphi function IDE_FirstSelectedObject(var ObjectType, ObjectOwner, ObjectName, SubObject: PChar): Bool This function will return the details of the first selected in the Browser. The function will return false if no items are selected. Use in combination with IDE_NextSelectedObject to determine all selected items. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_FirstSelectedObject)(char *ObjectType, char *ObjectOwner, char *ObjectName, char *SubObject); /* Delphi function IDE_NextSelectedObject(var ObjectType, ObjectOwner, ObjectName, SubObject: PChar): Bool This function can be called after a call to IDE_FirstSelectedObject to determine all selected objects. You can keep calling this function until it returns false. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_NextSelectedObject)(char *ObjectType, char *ObjectOwner, char *ObjectName, char *SubObject); /* Delphi function IDE_GetObjectSource (ObjectType, ObjectOwner, ObjectName: PChar): PChar Returns the source for the specified object. This function will only return source for objects that actually have source (packages, views, …). $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetObjectSource)(char *ObjectType, char *ObjectOwner, char *ObjectName); /* Delphi function IDE_GetWindowCount: Integer Returns the number of child windows in PL/SQL Developer. In combination with IDE_SelectWindow you can communicate with all child windows. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetWindowCount)(); /* Delphi function IDE_SelectWindow(Index: Integer): Bool This function will ‘select’ one of PL/SQL Developers child Windows. Index is the window number where 0 is the top child window. The return value will indicate if the window existed. Normally all window related functions communicate with the active child window. With this function you can select any window and all windowrelated IDE functions will refer to the selected window. Note: IDE_SelectWindow does not actually bring the window to front, you need IDE_ActivateWindow to do that. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SelectWindow)(int Index); /* Delphi function IDE_ActivateWindow(Index: Integer): Bool Brings the Indexth child window with to front. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ActivateWindow)(int Index); /* Delphi function IDE_WindowIsModified: Bool Returns if the contents of the window is modified. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_WindowIsModified)(); /* Delphi function IDE_WindowIsRunning: Bool Returns if there is anything running in the current window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_WindowIsRunning)(); /* Delphi procedure IDE_SplashCreate(ProgressMax: Integer) Creates an empty splash screen (the one you see when PL/SQL Developer is starting or printing) which allows you to show some kind of progress on lengthy operations. If the ProgressMax parameter is larger then 0, a progress bar is displayed which you can advance with the IDE_SplashProgress function. Note: There can only be one splash screen active at a time. If a splash screen is created while one was active, the first one will get re-used. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SplashCreate)(int ProgressMax); /* Delphi procedure IDE_SplashHide Hides the splash screen. This function will work on any splash screen, you can even hide the one created by PL/SQL Developer. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SplashHide)(); /* Delphi procedure IDE_SplashWrite(s: string) Add text to the splash screen. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SplashWrite)(char *s); /* Delphi procedure IDE_SplashWriteLn(s: string) Add text to the splash screen beginning on the next line. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SplashWriteLn)(char *s); /* Delphi procedure IDE_SplashProgress(Progress: Integer) If the splash screen was created with a progress bar, you can indicate progress with this function. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SplashProgress)(int Progress); /* Delphi function IDE_TemplatePath: PChar This function returns the path where the templates are located. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TemplatePath)(); /* Delphi function IDE_SetText(Text: PChar): Bool Sets the text in the editor of current window. If this failed for some reason (ReadOnly?), the function returns false. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetText)(char *Text); /* Delphi function IDE_SetStatusMessage(Text: PChar): Bool Places a message in the status bar of the current window, returns false if the window did not have a status bar. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetStatusMessage)(char *Text); /* Delphi function IDE_SetErrorPosition(Line, Col: Integer): Bool Highlights the given line and places the cursor at the given position. This will only work when the active window is a procedure window, if not, the function returns false. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetErrorPosition)(int Line, int Col); /* Delphi procedure IDE_ClearErrorPositions Resets the highlighted lines. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_ClearErrorPositions)(); /* Delphi function IDE_GetCursorWordPosition: Integer This function returns the location of the cursor in the word after a call to IDE_GetCursorWord. Possible return values: 0: Unknown 1: Cursor was at start of word 2: Cursor was somewhere in the middle 3: Cursor was at the end $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetCursorWordPosition)(); /* Delphi function IDE_Perform(Param Integer): Bool This function allows you to perform a specific action as if the menu item as specified in Param was selected. The following values are supported: 1: Execute 2: Break 3: Kill 4: Commit 5: Rollback 6: Print $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_Perform)(int Param); /* Delphi function IDE_GetCustomKeywords: PChar Returns a list of all keywords as entered in the ‘custom keywords’ option in the Editor preference. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetCustomKeywords)(); /* Delphi procedure IDE_SetCustomKeywords(Keywords: PChar) Fills the custom keywords with the words in the Keywords parameter. Words should be separated by cr/lf. The currently used keywords will be overwritten. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetCustomKeywords)(char *Keywords); /* Delphi procedure IDE_SetKeywords(ID, Style: Integer;Keywords: PChar) Adds a number of keywords with a specific style. This function is more specific then IDE_SetCustomKeywords because this one can set multiple sets of keywords for different highlighting styles. ID should be the PlugIn ID as returned by the IdentifyPlugIn function. Style can be one of the following values: 10: Custom 11: Keywords 12: Comment 13: Strings 14: Numbers 15: Symbols Keywords is a cr/lf separated list of words. You can define one list per style. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetKeywords)(int ID, int Style, char *Keywords); /* Activates the keywords as defined by the IDE_SetKeywords function. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_ActivateKeywords)(); /* Delphi procedure IDE_RefreshMenus(ID: Integer) When this function is called, all menus for this Plug-In are removed and CreateMenuItem will be called to build a new set of menus. This only makes sense if you supply a different set of menu-items. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_RefreshMenus)(int ID); /* Delphi procedure IDE_SetMenuName(ID, Index: Integer;Name: PChar) This function allows you to rename a certain menu-item. ID is the Plug-In ID, Index is the Menu number and name is the new menu name. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetMenuName)(int ID, int Index, char *Name); /* Delphi procedure IDE_SetMenuCheck(ID, Index: Integer;Enabled: Bool) You can display or remove a check mark for a menu-item. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetMenuCheck)(int ID, int Index, BOOL Enabled); /* Delphi procedure IDE_SetMenuVisible(ID, Index: Integer;Enabled: Bool) With this function you can hide or show a specific menu. You can use this instead of IDE_MenuState. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetMenuVisible)(int ID, int Index, BOOL Enabled); /* Delphi function IDE_GetMenulayout: PChar Returns a list of all standard PL/SQL Developer menu items. Items are separated by cr/lf and child menu level is indicated by a number of spaces. You can use this function to build an advanced user configuration dialog where the user could be able to select place where he wants to insert the Plug-In menus. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetMenulayout)(); /* Delphi procedure IDE_CreatePopupItem(ID, Index: Integer;Name, ObjectType: PChar) With this function you can add items to certain popup menus. The ID is the Plug-In ID and the index is the menu index. You can pass any number as the menu index, it can be an existing menu (as used by CreateMenuItem) or anything else. If the popup menu gets selected, OnMenuClick is called with the corresponding index. The Name is the menu name as it will be displayed. The ObjectType determines in which popup menus this item will be displayed. Some possible values are: ‘TABLE’, ‘VIEW’, ‘PACKAGE’, etc. Version 301 and higher If you pass one of the following values as ObjectType, you can add items to specific Windows. PROGRAMWINDOW SQLWINDOW TESTWINDOW COMMANDWINDOW Version 400 and higher You can add popup items to Object Browser items like Tables, Views, etc. by passing their name as ObjectType. Version 510 and higher If you want to create popup menus for multiple selected items (of the same object type), you can add a + to the ObjectType parameter like ‘TABLE+’, ‘VIEW+’, etc. The OnMenuClick will be called for every selected item, and the GetPopupObject will return the correct details. Version 700 and higher Supports Popup for the Session Window with the SESSIONWINDOW ObjectType. (see also IDE_GetSessionValue) Version 712 and higher Supports Popup for result grids with SQLRESULT Version 800 and higher Supports Popup for file browser with FILE $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void* (*IDE_CreatePopupItem)(int ID, int Index, char *Name, char *ObjectType); /* Delphi function IDE_SetConnection(Username, Password, Database: PChar): Bool This function allows you to reconnect PL/SQL Developer as another user. The return value indicates if the connection was successful. The function will fail if there is a childwindow with an active query. Also see IDE_SetConnectionAs $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetConnection)(char *Username, char *Password, char *Database); /* Delphi procedure IDE_GetObjectInfo(AnObject: PChar;var ObjectType, ObjectOwner, ObjectName, SubObject: PChar) This function returns Oracle information about the item in the AnObject parameter. The SubObject returns the name of the procedure if the Object is a packaged procedure. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetObjectInfo)(char *AnObject, char **ObjectType, char **ObjectOwner, char **ObjectName, char **SubObject); /* Delphi function IDE_GetBrowserItems(Node: PChar;GetItems: Bool): PChar Returns a cr/lf separated list of items from the Object Browser. The Node parameter determines which items are returned. This can be one of the main items like TABLES, but you can also us a slash to get more specific items like TABLES/DEPT/COLUMNS. The GetItems boolean determines if PL/SQL Developer will fetch these values from the database if the item has not been opened yet in the Browser. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetBrowserItems)(char *Node, BOOL GetItems); /* Delphi function IDE_TranslateItems(Group: PChar): PChar Function for translating items. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TranslateItems)(char *Group); /* Delphi function IDE_TranslateString(ID, Default, Param1, Param2: PChar): PChar Function for translating items. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_TranslateString)(char *ID, char *Default, char Param1, char Param2); /* Delphi function IDE_SaveRecoveryFiles: Bool PL/SQL Developer has a preference to save all opened files on a time interval, and/or when an Execute is performed. In case of a crash (from the system, Oracle or PL/SQL Dev), the user will be able to recover the edited files. If the Plug-In can do things that have a possible risk of causing a crash, you can call this function to protect the user’s work. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SaveRecoveryFiles)(); /* Delphi function IDE_GetCursorX: Integer Returns the (1 based) character position of the cursor in the current editor. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetCursorX)(); /* Delphi function IDE_GetCursorY: Integer Returns the (1 based) line position of the cursor in the current editor. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetCursorY)(); /* Delphi procedure IDE_SetCursor(X, Y: Integer) Set the cursor in the current editor. If the X or Y parameter is 0, the position will not change. This function will also update the position display in the statusbar. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetCursor)(int X, int Y); /* Delphi function SYS_Version: Integer Returns the PL/SQL Developer main and subversion, for example 210 for version 2.1.0. This might be useful if you want to use functions that are not available in all versions. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SYS_Version)(); /* Delphi function SYS_Registry: PChar Returns the registry root name of PL/SQL Developer in HKEY_CURRENT_USER (usually “Software\PL/SQL Developer”). If you want to save your settings in the registry, you can create a section within the PL/SQL Developer section. Note: In PL/SQL Developer 3.1, the registry section is moved to: (“Software\Allround Automations\PL/SQL Developer”) $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SYS_Registry)(); /* Delphi function SYS_RootDir: PChar The directory where PL/SQL Developer is installed, for example “C:\Program Files\PLSQL Developer”. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SYS_RootDir)(); /* Delphi function SYS_OracleHome: PChar The Oracle directory, for example “C:\Orawin95” $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SYS_OracleHome)(); /* Delphi function SYS_OCIDLL: PChar Returns the path of the OCI DLL that is used by PL/SQL Developer. If you want to initialize a new session, you might want to use this value if you want to make sure you’re using the same OCI version. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SYS_OCIDLL)(); /* Delphi function SYS_OCI8Mode: Bool Returns True if PL/SQL Developer is currently connected in OCI8 Mode (Net8). $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL* (*SYS_OCI8Mode)(); /* Delphi function SYS_XPStyle: Bool Returns if PL/SQL Developer is currently using the visual XP style. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL* (*SYS_XPStyle)(); /* Delphi function SYS_TNSNAMES(Param: PChar): PChar If Param is empty, the function will return the full tnsnames filename. If Param has a value, the connection details of the alias as specified by Param is returned. If Param is *, the connection details of the current connection are returned). The return value can look like: TEST = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = p2800)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = AAA) ) ) $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SYS_TNSNAMES)(char *Param); /* Delphi function SYS_DelphiVersion: Integer Returns the Delphi version used to build PL/SQL Developer. Only useful for very specific functions. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SYS_DelphiVersion)(); /* Delphi procedure IDE_MenuState(ID, Index: Integer;Enabled: Bool) Use this function to enable or disable a menu. The ID is the Plug-In ID, which is given by the IdentifyPlugIn function. The Index is the menu index, which the menu was related to by the CreateMenuItem function. The Enabled boolean determines if the menu item is enabled or grayed. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_MenuState)(int ID, int Index, BOOL Enabled); /* Delphi function IDE_Connected: Bool Returns a boolean that indicates if PL/SQL Developer is currently connected to a database. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_Connected)(); /* Delphi procedure IDE_GetConnectionInfo(var Username, Password, Database: PChar) Returns the username, password and database of the current connection. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_GetConnectionInfo)(char **Username, char **Password, char **Database); /* Delphi procedure IDE_GetBrowserInfo(var ObjectType, ObjectOwner, ObjectName: PChar) Returns information about the selected item in the Browser. If no item is selected, all items are empty. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_GetBrowserInfo)(char **ObjectType, char **ObjectOwner, char **ObjectName); /* Delphi function IDE_GetWindowType: Integer Returns the type of the current window. 1 = SQL Window 2 = Test Window 3 = Procedure Window 4 = Command Window 5 = Plan Window 6 = Report Window 0 = None of the above $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetWindowType)(); /* Delphi function IDE_GetAppHandle: Integer Returns the Application handle of PL/SQL Developer $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetAppHandle)(); /* Delphi function IDE_GetWindowHandle: Integer Returns the handle of PL/SQL Developers main window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetWindowHandle)(); /* Delphi function IDE_GetClientHandle: Integer Returns the handle of PL/SQL Developers client window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetClientHandle)(); /* Delphi function IDE_GetChildHandle: Integer Returns the handle of the active child form $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetChildHandle)(); /* Delphi procedure IDE_Refresh Resets the state of the menus, buttons and the active window. You can call this function if you made some changes that affect the state of a menu or window which are unnoticed by PL/SQL Developer. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_Refresh)(); /* Delphi procedure IDE_CreateWindow(WindowType: Integer;Text: PChar; Execute: Bool) Creates a new window. The Text parameter contains text that is placed in the window. If the Execute Boolean is true, the Window will be executed. WindowType can be one of the following values: 1 = SQL Window 2 = Test Window 3 = Procedure Window 4 = Command Window 5 = Plan Window 6 = Report Window Version 800 and higher 7 = HTML Window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_CreateWindow)(int WindowType, char *Text, BOOL Execute); /* Delphi function IDE_OpenFile(WindowType: Integer;Filename: PChar): Bool Creates a window of type WindowType and loads the specified file. WindowType can be one of the following values: 1 = SQL Window 2 = Test Window 3 = Procedure Window 4 = Command Window The function returns True if successful. Version 301 and higher If you pass 0 as WindowType, PL/SQL Developer will try to determine the actual WindowType on the extension of the filename. Version 800 and higher 5 = Plan Window 6 = Report Window 7 = HTML Window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_OpenFile)(int WindowType, char *Filename); /* Delphi function IDE_SaveFile: Bool This function saves the current window. It returns True if successful. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SaveFile)(); /* Delphi function IDE_Filename: PChar Return the filename of the current child window. See also IDE_SetFilename() $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_Filename)(); /* Delphi procedure IDE_CloseFile Closes the current child window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_CloseFile)(); /* Delphi procedure IDE_SetReadOnly(ReadOnly: Bool) Set the ReadOnly status of the current Window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetReadOnly)(BOOL ReadOnly); /* Delphi function IDE_ReloadFile: Bool Forces the active child window to reload its file from disk. Note: In PL/SQL Developer 4 there will no longer be a warning message when modifications were made. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ReloadFile)(); /* Delphi procedure IDE_SetFilename(Filename: PChar) Set the filename of the active child window. The filename should contain a valid path, but the file does not need to exist. The new filename will be used when the file is saved. If the Filename parameter is an empty string, the Window will behave as a new created Window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_SetFilename)(char *Filename); /* Delphi function IDE_GetText: PChar Retrieves the text from the current child window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetText)(); /* Delphi function IDE_GetSelectedText: PChar Retrieves the selected text from the current child window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetSelectedText)(); /* Delphi function IDE_GetCursorWord: PChar Retrieves the word the cursor is on in the current child window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetCursorWord)(); /* Delphi function IDE_GetEditorHandle: Integer Returns the handle of the editor of the current child window. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetEditorHandle)(); /* Delphi function IDE_Authorized(Category, Name, SubName: PChar): Bool In PL/SQL Developer 6 we introduced the concept of Authorization. You should test if a specific feature is allowed for the current user with this function. In the Category parameter you can specify one of the main categories (objects, menus, system). The name parameter specifies the item (session.kill or objects.drop). Some items have a subname, like objects.drop with the different objects. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_Authorized)(char *Category, char *Name, char *SubName); /* Delphi function IDE_WindowAllowed(WindowType: Integer;ShowErrorMessage: Bool): Bool For a quick check if authorization allows the Plug-In to create a specific function, you can use this function. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_WindowAllowed)(int WindowType, BOOL ShowErrorMessage); /* Delphi function IDE_Authorization: Bool Returns if authorization is enabled or not. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_Authorization)(); /* Delphi function IDE_AuthorizationItems(Category: PChar): PChar If you want a list off all available authorization items, you can call this function. It will return a cr/lf separated list. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_AuthorizationItems)(char *Category); /* Delphi procedure IDE_AddAuthorizationItem(PlugInID: Integer;Name: PChar) If you want to add items to the authorization list to allow them to be managed through the authorization option, you can use this function. Pass the PlugInID to identify your Plug-In, and pass the Name parameter with the item you want to add. The name should be unique, so you should prefix it with the name the Plug-In, for example: MyPlugIn.Create New Command All items will be added in the PlugIns category, so if you want to test if this feature is allowed you should call: IDE_Authorized('PlugIns ', ' MyPlugIn.Create New Command') $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*IDE_AddAuthorizationItem)(int PlugInID, char *Name); /* Delphi function IDE_GetPersonalPrefSets: PChar Returns a list of all personal preference sets. If you to have the Plug-In to use different preferences depending on the current connection, you can use this function to build a list of possible preference sets. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetPersonalPrefSets)(); /* Delphi function IDE_GetDefaultPrefSets: PChar Returns a list of all default preference sets. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetDefaultPrefSets)(); /* Delphi function IDE_GetPrefAsString(PlugInID: Integer; PrefSet, Name: PChar; Default: PChar): PChar Read a Plug-In preference from the preferences. In PL/SQL Developer 6, personal preferences are stored in files, not in the registry. You can still use the registry, but if you want to store your preferences in a shared location, you can use this function. Pass the PlugInID you received with the IdentifyPlugIn call. The PrefSet parameter can be empty to retrieve default preferences, or you can specify one of the existing preference sets. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetPrefAsString)(int PlugInID, char *PrefSet, char *Name, char *Default); /* Delphi function IDE_GetPrefAsInteger(PlugInID: Integer;PrefSet, Name: PChar; Default: Integer): Integer As IDE_GetPrefAsString, but for integers. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetPrefAsInteger)(int PlugInID, char *PrefSet, char *Name, BOOL Default); /* Delphi function IDE_GetPrefAsBool(PlugInID: Integer; PrefSet, Name: PChar; Default: Bool): Bool As IDE_GetPrefAsString, but for booleans. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_GetPrefAsBool)(int PlugInID, char *PrefSet, char *Name, BOOL Default); /* Delphi function IDE_SetPrefAsString(PlugInID: Integer; PrefSet, Name: PChar; Value: PChar): Bool Set a Plug-In preference. Pass the PlugInID you received with the IdentifyPlugIn call. The PrefSet parameter can be empty to set default preferences, or you can specify one of the existing preference sets. The return value indicates if the function succeeded. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetPrefAsString)(int PlugInID, char *PrefSet, char *Name, char *Value); /* Delphi function IDE_SetPrefAsInteger(PlugInID: Integer;PrefSet, Name: PChar; Value: Integer): Bool As IDE_SetPrefAsString, but for integers. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetPrefAsInteger)(int PlugInID, char *PrefSet, char *Name, int Value); /* Delphi function IDE_SetPrefAsBool(PlugInID: Integer; PrefSet, Name: PChar; Value: Bool): Bool As IDE_SetPrefAsString, but for booleans. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_SetPrefAsBool)(int PlugInID, char *PrefSet, char *Name, BOOL Value); /* Delphi function IDE_GetGeneralPref(Name: PChar): PChar Returns the value of a preference. The names can be found in the preference ini file under the [Preferences] section. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetGeneralPref)(char *Name); /* Delphi function SQL_GetDBMSGetOutput: PChar Returns sys.dbms_output for the current (PlugIn specific) session. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SQL_GetDBMSGetOutput)(); /* Delphi procedure SQL_SetVariable(Name, Value: PChar) This function declares a variable. Call this for al variables you use in the statement you pass in SQL_Execute. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*SQL_SetVariable)(char *Name, char *Value); /* Delphi function SQL_GetVariable(Name: PChar): PChar This function will return the value of a variable. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SQL_GetVariable)(char *Name); /* Delphi procedure SQL_ClearVariables Clear all declared variables. If you are finished doing a query it is a good idea to call this function to prevent errors for the next execute. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*SQL_ClearVariables)(); /* Delphi function IDE_GetReadOnly: Bool Get the ReadOnly status of the current Window $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_GetReadOnly)(); /* Delphi function IDE_ExecuteSQLReport(SQL: PChar;Title: PChar; Updateable: Bool): Bool This function will execute a query (SQL parameter) and display the result in a ‘result only’ SQL Window. Title will be used as the window name and the Updateable parameter determines if the results are updateable. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_ExecuteSQLReport)(char *SQL, char *Title, BOOL Updateable); /* Delphi function IDE_PlugInSetting(PlugInID: Integer; Setting, Value: PChar): Bool Make a Plug-In specific setting: NOFILEDATECHECK TRUE|FALSE Determines if PL/SQL Developer checks for changes in files (default true) CHARMODE ANSI|UTF8|UTF8BOM Determines how PChar parameters are passed through the Plug-In interface. Since version 7.1 supports editing of Unicode, but the interface only supports normal characters, you can choose to support UTF8 encoding. The UTF8BOM encoding will precede the characters with a BOM indicator when text contains Unicode. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_PlugInSetting)(int PlugInID, char *Setting, char *Value); /* Delphi IDE_GetProcOverloadCount(Owner, PackageName, ProcedureName: PChar): Integer Returns the number of overloads for a specific procedure. Result < 0 = Procedure doesn't exist Result > 0 = overload count $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_GetProcOverloadCount)(char *Owner, char *PackageName, char *ProcedureName); /* Delphi IDE_SelectProcOverloading(Owner, PackageName, ProcedureName: PChar): Integer Shows a dialog to allow the user to select an overloaded procedure. Result < 0 = Cancel Result 0 = No overloadings Result > 0 = Overload index $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*IDE_SelectProcOverloading)(char *Owner, char *PackageName, char *ProcedureName); /* Delphi function IDE_GetSessionValue(Name: PChar): PChar This function will return one of the Session parameters as you see in the grid of the session tool. You will only get a result if the Session Window is active, so this will only work from a Popup menu created for the SESSIONWINDOW object. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*IDE_GetSessionValue)(char *Name); /* Delphi function IDE_CheckDBVersion(Version: PChar): Boolean You can use this function to check if the database is equal or higher then the specified version. The parameter should be in the format aa.bb, like 09.02 or 10.00. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*IDE_CheckDBVersion)(char *Version); /* Delphi function SQL_Execute(SQL: PChar): Integer Executes the statement defined in the SQL parameter. The function returns 0 if successful, else the Oracle error number. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SQL_Execute)(char *SQL); /* Delphi function SQL_FieldCount: Integer Returns the number of fields after a SQL_Execute. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SQL_FieldCount)(); /* Delphi function SQL_Eof: Bool Returns if there are any more rows to fetch. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*SQL_Eof)(); /* Delphi function SQL_Next: Integer Returns the next row after a SQL_Execute. The function returns 0 if successful, else the Oracle error number. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SQL_Next)(); /* Delphi function SQL_Field(Field: Integer): PChar Returns the field specified by the Field parameter. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SQL_Field)(int Field); /* Delphi function SQL_FieldName(Field: Integer): PChar Returns the fieldname specified by the Field parameter. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SQL_FieldName)(int Field); /* Delphi function SQL_FieldIndex(Name: PChar): Integer Converts a fieldname into an index, which can be used in the SQL_Field, SQL_FieldName and SQL_FieldType functions. If the field does not exist, the return value is -1. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SQL_FieldIndex)(char *Name); /* Delphi function SQL_FieldType(Field: Integer): Integer Return the fieldtype of a field. 3 = otInteger 4 = otFloat 5 = otString 8 = otLong 12 = otDate 24 = otLongRaw $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern int(*SQL_FieldType)(int Field); /* Delphi function SQL_ErrorMessage: PChar This function will return the error message for any error that occurred during: SQL_Execute SQL_Eof SQL_Next IDE_SetConnection $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern char* (*SQL_ErrorMessage)(); /* Delphi function SQL_UsePlugInSession(PlugInID: Integer): Bool Normally, the SQL functions will use the main PL/SQL Developer Oracle session. If you want to make sure you don’t interfere with other transactions, and you want the PlugIn to use a private session, call this function. The return value indicates if the function succeeded. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*SQL_UsePlugInSession)(int PlugInID); /* Delphi procedure SQL_UseDefaultSession(PlugInID: Integer) This function will cancel the previous function and set the Oracle session back to default. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern void(*SQL_UseDefaultSession)(int PlugInID); /* Delphi function SQL_CheckConnection: Bool Forces PL/SQL Developer to check if the current connection to the database is still open (and tries a re-connect if necessary). The return value indicates if there is a connection. $ Scratch by Jianwen Luo at: 2011-03-14 10:37:20 $ */ extern BOOL(*SQL_CheckConnection)(); /****************************************************************************** / /*All enent functions declare */ /* Delphi function IdentifyPlugIn(ID: Integer): PChar This function receives a Plug-In ID from PL/SQL Developer and should return a description for the Plug-In. The returned description should be unique for your Plug-In and will be displayed in the Plug-In configuration dialog. The ID identifies your Plug-In and can be used in other callback functions. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* IdentifyPlugIn(int ID); /* Delphi function CreatMenuItem(Index: Integer): PChar This function will be called with an Index ranging from 1 to 99. For every Index you can return a string that creates a new menu-item in PL/SQL Developer. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* CreateMenuItem(int Index); /* Delphi procedure OnMenuClick(Index: Integer) This function is called when a user selected a menu-item created with the CreateMenuItem function and the Index parameter has the value (1 to 99) it is related to. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnMenuClick(int Index); /* Delphi procedure OnCreate This function is called when the Plug-In is loaded into memory. You can use it to do some one-time initialization. PL/SQL Developer is not logged on yet and you can’t use the callback functions, so you are limited in the things you can do. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnCreate(); /* Delphi procedure OnActivate OnActivate gets called after OnCreate. However, when OnActivate is called PL/SQL Developer and the Plug-In are fully initialized. This function is also called when the Plug-In is enabled in the configuration dialog. A good point to enable/disable menus. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnActivate(); /* Delphi procedure OnDeactivate This is the counterpart of the OnActivate. It is called when the Plug-In is de-activated in the configuration dialog. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnDeactivate(); /* Delphi procedure OnDestroy This is the counterpart of the OnCreate. You can dispose of anything you created in the OnCreate. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnDestroy(); /* Delphi function CanClose: Bool This will be called when PL/SQL Developer is about to close. If your PlugIn is not ready to close, you can show a message and return False. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL CanClose(); /* Delphi procedure AfterStart Called after all Plug-Ins are loaded and PL/SQL Developer is finished starting. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void AfterStart(); /* Delphi procedure OnBrowserChange If your Plug-In depends on a selected item in the Browser, you can use this function to enable/disable menu-items. This function is called on every change in the Browser. You can use the IDE_GetBrowserInfo callback function to determine if the selected item is of interest to you. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnBrowserChange(); /* Delphi procedure OnWindowChange This function is called if PL/SQL Developer child windows change focus. You can use the IDE_GetWindowType callback to determine the active child window type. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnWindowChange(); /* Delphi procedure OnWindowCreate(WindowType: Integer) This function is called directly after a new window is created. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnWindowCreate(int WindowType); /* Delphi procedure OnWindowCreated(WindowType: Integer) This function is called after a new window is created. The difference with the “Create” function is that the Window is now completely initialized. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnWindowCreated(int WindowType); /* Delphi function OnWindowClose(WindowType: Integer; Changed: BOOL): Integer This function allows you to take some action before a window is closed. You can influence the closing of the window with the following return values: 0 = Default behavior 1 = Ask the user for confirmation (like the contents was changed) 2 = Don’t ask, allow to close without confirmation The Changed Boolean indicates the current status of the window. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ int OnWindowClose(int WindowType, BOOL Changed); /* Delphi function BeforeExecuteWindow(WindowType: Integer): Bool This function is called before a Window is executed. Nothing is actually executed yet, and you can cancel execution by returning false. When you do return false, please give some feedback to the user why execution was cancelled. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL BeforeExecuteWindowe(int WindowType); /* Delphi procedure AfterExecuteWindow(WindowType, Result: Integer) When execution is finished, this function is called. The return parameter will indicate how execution finished: 0 = Finished with error 1 = Finished with the option to continue (like “next page” in the SQL Window) 2 = Finished successfully $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void AfterExecuteWindow(int WindowType, int Result); /* Delphi procedure OnConnectionChange This function is called when the user logs on to a different database or logs off. You can use the IDE_Connected and IDE_GetConnectionInfo callback to get information about the current connection. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnConnectionChange(); /* Delphi procedure OnPopup(ObjectType, ObjectName: PChar) This function is called when a context sensitive popup is about to be displayed. It gives you the opportunity to do something with the menus you have created with the IDE_CreatePopupMenuItem callback. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnPopup(char *ObjectType, char *ObjectName); /* Delphi procedure OnMainMenu(MenuName: PChar) This function is called when a main menu is selected (when it drops down). You can use this event to activate your Plug-In menu(s) if none of the other events are appropriate. The MenuName parameter is the name of the main menu item that was selected. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnMainMenu(char *MenuName); /* Delphi function OnTemplate(Filename: PChar; var Data: PChar): Bool This function is called before a template is executed. This gives you a chance to modify the contents in the Data parameter. If you return false, the template is cancelled. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL OnTemplate(char *Filename, char **Data); /* Delphi procedure OnFileLoaded(WindowType, Mode: Integer) Called after a file is loaded. The mode parameter can identify the following: 1: recovery file (from a crash) 2: backup file (normal file backup with a ~ extension) $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnFileLoaded(int WindowType, int Mode); /* Delphi procedure OnFileSaved(WindowType, Mode: Integer) Called after a file is saved. The mode parameter can identify the following: 1: recovery file (from a crash) 2: backup file (normal file backup with a ~ extension) $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void OnFileSaved(int WindowType, int Mode); /* Delphi function About: PChar This function allows you to display an about dialog. You can decide to display a dialog yourself (in which case you should return an empty text) or just return the about text. In PL/SQL Developer 3.1 there is an about button in the Plug-In configuration dialog. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* About(); /* Delphi procedure Configure If the Plug-In has a configure dialog you could use this function to activate it. This will allow a user to configure your Plug-In using the configure button in the Plug-In configuration dialog. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void Configure(); /* Delphi procedure CommandLine(FeedbackHandle: Integer; Command, Params: PChar) You can use this function if you want the Plug-In to be able to accept commands from the command window. See IDE_CommandFeedback for how to return messages to the command window. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void CommandLine(int FeedbackHandle, char *Command, char *Params); /* Delphi function PlugInName: PChar The PlugIn name (if defined) will be used for online updates, and as name for command window PlugIn commands. If you want your PlugIn to be handled by online updates, please contact support. If this function is not defined, the PlugInName will be the dll filename. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* PlugInName(); /* Delphi function PlugInSubName: PChar The subname will be added to the PlugInName. Possible values are ‘Trial’ or ‘Beta’. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* PlugInSubName(); /* Delphi function PlugInShortName: PChar The short name is specifically for command window PlugIn commands. This allows you to specify a name that can be entered quickly. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* PlugInShortName(); /* Delphi function RegisterFileSystem: PChar Use this function if you want your Plug-In to load/save files somewhere ‘external’. If you use this function you should return a description that identifies your filesystem (like FTP for the FTP Plug-in). See the chapter about External File Systems. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* RegisterFileSystem(); /* Delphi function DirectFileLoad: function(var Tag, Filename: PChar;WindowType: Integer): PChar This function will get called when a file will be directly loaded without a file dialog. This is needed if a user selects a file from the recent used files list. The Parameters indicate the file that you have to load and the return value is the file data. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* DirectFileLoad(); /* Delphi function DirectFileSave(var Tag, Filename: PChar; Data: PChar;WindowType: Integer): Bool This function will be called when ‘File Save’ is selected (not ‘File Save As…). You should save the data as specified in the parameters and return True if everything was successful. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL DirectFileSave(); /* Delphi function RegisterExport: PChar Use this function if you want to add an export option for (result) grids. The name you return will be the name that is displayed in the popup menus (next to html, xml, …). See the chapter about adding export options. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ char* RegisterExport(); /* Delphi function ExportInit: Boolean First call after an export request. You can ask the user for a filename and/or initialize variables. Return False if you want to cancel the export. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL ExportInit(); /* Delphi procedure ExportFinished;The export has finished. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void ExportFinished(); /* Delphi function ExportPrepare: Boolean This function allows you to prepare for the actual data. All values received with Exportdata before this function is called are column headers, and all values received after ExportPrepare is data. The return value allows you to signal if the prepare was processed correctly. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL ExportPrepare(); /* Delphi function ExportData(Value: PChar): Boolean One cell of data, this can be the column description or the actual data. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ BOOL ExportData(char *Value); /* Delphi procedure RegisterCallback(Index: Integer; Addr: Pointer) There are several functions in PL/SQL Developer that you can use from your Plug-In. With this function you can get access to the callback functions you need. The Index is related to a specific callback function while the Addr parameter holds the address to this function. $ Scratch by Jianwen Luo at: 2011-03-14 10:41:16 $ */ void RegisterCallback(int Index, void *Addr); #endif //__PLUGIN_H__
插件的脚本实现框架示例,此处为自己开发的一个小功能,通过Oracle的数据字典表得到表结构的个性化文本配置信息。
plugInID = 0 --Identify of plugin specified by IDE -- Tab type returned by IDE_TabInfo() PLSQL_TT_FUNCTION = "Function" PLSQL_TT_PROCEDURE = "Procedure" PLSQL_TT_TRIGGER = "Trigger" PLSQL_TT_JAVA_SOURCE = "Java source" PLSQL_TT_PACKAGE_SPEC = "Package" PLSQL_TT_PACKAGE_BODY = "Package body" PLSQL_TT_TYPE_SPEC = "Type" PLSQL_TT_TYPE_BODY = "Type body" -- window type PLSQL_WT_UNKNOWN = 0 PLSQL_WT_SQL = 1 PLSQL_WT_TEST = 2 PLSQL_WT_PROCEDURE = 3 PLSQL_WT_COMMAND = 4 PLSQL_WT_PLAN = 5 PLSQL_WT_REPORT = 6 -- Cursor word position PLSQL_CWP_UNKNOWN = 0 PLSQL_CWP_CURSOR_START_WORD = 1 PLSQL_CWP_CURSOR_WORD = 2 PLSQL_CWP_CURSOR_END_WORD = 3 -- Perform PLSQL_PERFORM_EXECUTE = 1 PLSQL_PERFORM_BREAK = 2 PLSQL_PERFORM_KILL = 3 PLSQL_PERFORM_COMMIT = 4 PLSQL_PERFORM_ROLLBACK = 5 PLSQL_PERFORM_PRINT = 6 -- Keyword style PLSQL_KWS_CUSTOM = 10 PLSQL_KWS_KEYWORDS = 11 PLSQL_KWS_COMMENT = 12 PLSQL_KWS_STRINGS = 13 PLSQL_KWS_NUMBERS = 14 PLSQL_KWS_SYMBOLS = 15 -- Popup PLSQL_POPUP_PROGRAMWINDOW = "PROGRAMWINDOW" PLSQL_POPUP_SQLWINDOW = "SQLWINDOW" PLSQL_POPUP_TESTWINDOW = "TESTWINDOW" PLSQL_POPUP_COMMANDWINDOW = "COMMANDWINDOW" -- Refresh object PLSQL_REFRESH_OBJECT_CREATED = 1 PLSQL_REFRESH_OBJECT_MODIFIED = 2 PLSQL_REFRESH_OBJECT_DELETED = 3 -- Key simulation PLSQL_KP_SHIFT = 1 PLSQL_KP_ALT = 2 PLSQL_KP_CTRL = 3 -- Beautifier options PLSQL_BO_AfterCreating = 1 PLSQL_BO_AfterLoading = 2 PLSQL_BO_BeforeCompiling = 4 PLSQL_BO_BeforeSaving = 8 -- SQL field type PLSQL_FT_Integer = 3 PLSQL_FT_Float = 4 PLSQL_FT_String = 5 PLSQL_FT_Long = 8 PLSQL_FT_Date = 12 PLSQL_FT_LongRaw = 24 -- WindowType can be one of the following values WINDOWTYPE_SQL_WINDOW = 1 WINDOWTYPE_TEST_WINDOW = 2 WINDOWTYPE_PROCEDURE_WINDOW = 3 WINDOWTYPE_COMMAND_WINDOW = 4 WINDOWTYPE_PLAN_WINDOW = 5 WINDOWTYPE_REPORT_WINDOW = 6 WINDOWTYPE_HTML_WINDOW = 7 --Define oracle object types OBJECT_TYPE_TABLE = "TABLE" OBJECT_TYPE_VIEW = "VIEW" OBJECT_TYPE_FUNCTION = "FUNCTION" OBJECT_TYPE_PROCEDURE = "PROCEDURE" OBJECT_TYPE_PACKAGE = "PACKAGE" OBJECT_TYPE_TABLE_MULSEL = "TABLE+" OBJECT_TYPE_VIEW_MULSEL = "VIEW+" OBJECT_TYPE_FUNCTION_MULSEL = "FUNCTION+" OBJECT_TYPE_PROCEDURE_MULSEL = "PROCEDURE+" --Predefine menu indexes MENU_DDL_TRUCATE = 11 MENU_DDL_TABSRC_EXP = 12 MENU_DML_TABREC_EXP = 13 MENU_UTL_TAB_EXP = 14 MENU_UTL_CONNINFO = 15 MENU_UTL_PMSMETA = 16 MENU_UTL_SAVESRC = 17 MENU_UTL_TAB_BAK = 18 --Predefine menu separator MENU_SEPARATOR_1 = 1 MENU_SEPARATOR_2 = 2 MENU_SEPARATOR_3 = 3 MENU_SEPARATOR_4 = 4 MENU_SEPARATOR_5 = 5 MENU_SEPARATOR_6 = 6 MENU_SEPARATOR_7 = 7 MENU_SEPARATOR_8 = 8 MENU_SEPARATOR_9 = 9 MENU_SEPARATOR_10 = 10 --[[ Delphi function IdentifyPlugIn(ID: Integer): PChar This function receives a Plug-In ID from PL/SQL Developer and should return a description for the Plug-In. The returned description should be unique for your Plug-In and will be displayed in the Plug-In configuration dialog. The ID identifies your Plug-In and can be used in other callback functions. --]] function IdentifyPlugIn(ID) --Add your code here --ShowMessage("IdentifyPlugIn is called in lua script.") plugInID=ID return "Yet Another Plug-In 0.0.1" end --[[ Delphi function CreatMenuItem(Index: Integer): PChar This function will be called with an Index ranging from 1 to 99. For every Index you can return a string that creates a new menu-item in PL/SQL Developer. --]] function CreateMenuItem(Index) --Add your code here --ShowMessage("CreateMenuItem is called in lua script.") --Add a bundle of Yap menu ... local Result="" if Index == MENU_SEPARATOR_1 then Result = "Tools / -" elseif Index == MENU_UTL_CONNINFO then Result = "Tools / Yap / Connection information" elseif Index == MENU_SEPARATOR_2 then Result = "Tools / -" end return Result end --[[ Delphi procedure OnMenuClick(Index: Integer) This function is called when a user selected a menu-item created with the CreateMenuItem function and the Index parameter has the value (1 to 99) it is related to. --]] function OnMenuClick(Index) --Add your code here --ShowMessage("OnMenuClick is called in lua script.") --Response for Truncate menu if Index==MENU_DDL_TRUCATE then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then if 1 == ShowMessageOption("Truncate selected table "..objectOwner.."."..objectName..", are you sure?") then sqlStr="truncate table "..objectOwner.."."..objectName errCode = SQL_Execute(sqlStr) if errCode ~= 0 then ShowMessage(SQL_ErrorMessage()) end end end end --Response for connection information if Index==MENU_UTL_CONNINFO then if IDE_Connected() then userName,passWord,dataBase=IDE_GetConnectionInfo() asRole=IDE_GetConnectAs() if asRole=="" then asRole="Normal" end ShowMessage("Connected by "..userName.."/"..passWord.."@"..dataBase.." as "..asRole) else ShowMessage("Not connected") end end --Response for PMS Meta export if Index==MENU_UTL_PMSMETA then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then fileName=GetSaveFileName("Text File (*.txt)\0*.txt\0All File (*.*)\0*.*\0\0",objectName..".txt") if fileName~=nil and fileName~="" then ofd=io.open(fileName,"w") if ofd==nil then ShowMessage("Can not open specified file.") else result=WirtePMSMeta(objectOwner,objectName,ofd) if result==nil then ShowMessage("Can not write specified file.") end ofd:close() end end end end --Response for export table DDL (Simple) if Index==MENU_DDL_TABSRC_EXP then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then fileName=GetSaveFileName("SQL File (*.sql)\0*.sql\0All File (*.*)\0*.*\0\0",objectName..".sql") if fileName~=nil and fileName~="" then ofd=io.open(fileName,"w") if ofd==nil then ShowMessage("Can not open specified file.") else result=ExportTableSimpleDDL(objectOwner,objectName,ofd) if result == nil or string.len(result) == 0 then ShowMessage("Can not found source of specified object.") end ofd:close() end end end end --Response for export table records if Index==MENU_DML_TABREC_EXP then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then fileName=GetSaveFileName("SQL File (*.sql)\0*.sql\0All File (*.*)\0*.*\0\0",objectName..".sql") if fileName~=nil and fileName~="" then ofd=io.open(fileName,"w") if ofd==nil then ShowMessage("Can not open specified file.") else result=ExportTableRecords(objectOwner,objectName,ofd) if result == nil then ShowMessage("Can not create data of specified object.") end ofd:close() end end end end --Response for export table DDL and records if Index==MENU_UTL_TAB_EXP then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then fileName=GetSaveFileName("SQL File (*.sql)\0*.sql\0All File (*.*)\0*.*\0\0",objectName..".sql") if fileName~=nil and fileName~="" then ofd=io.open(fileName,"w") if ofd==nil then ShowMessage("Can not open specified file.") else result=ExportTableSimpleDDL(objectOwner,objectName,ofd) if result == nil then ShowMessage("Can not found source of specified object.") end result=ExportTableRecords(objectOwner,objectName,ofd) if result == nil then ShowMessage("Can not create data of specified object.") end ofd:close() end end end end --Response for save source as file if Index==MENU_UTL_SAVESRC then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() fileName=GetSaveFileName("SQL File (*.sql)\0*.sql\0All File (*.*)\0*.*\0\0",objectName..".sql") if fileName~=nil and fileName~="" then ofd=io.open(fileName,"w") if ofd==nil then ShowMessage("Can not open specified file.") else IDE_SplashCreate(100) IDE_SplashWriteLn("Save "..objectOwner.."."..objectName.." source to file '"..fileName.."'") IDE_SplashProgress(50) result=IDE_GetObjectSource(objectType,objectOwner,objectName) IDE_SplashProgress(80) if result == nil or string.len(result) == 0 then ShowMessage("Can not found source of specified object.") else ofd:write(result) end ofd:flush() ofd:close() IDE_SplashWriteLn("Completed") IDE_SplashProgress(100) IDE_SplashHide() end end end --Backup table data if Index==MENU_UTL_TAB_BAK then objectType,objectOwner,objectName,subObject,retCode=IDE_GetPopupObject() if objectType == OBJECT_TYPE_TABLE then sqlStr="select to_char(sysdate,'yyyymmdd') rq from dual" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to get sysdate infomation!") else dateStr=SQL_Field(SQL_FieldIndex("RQ")) if dateStr == nil or string.len(dateStr) == 0 then ShowMessage("Sysdate string is invalid!") else sqlStr="create table "..string.upper(objectOwner).."."..string.upper(objectName).."_"..dateStr.." as select * from "..string.upper(objectOwner).."."..string.upper(objectName) option=ShowMessageOption("Create a temporary table to store object's data, sure?\nSQL:"..sqlStr) if option == 1 then if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Create temporary table fault\n"..SQL_ErrorMessage()) end end end end end end end --[[ Delphi procedure OnCreate This function is called when the Plug-In is loaded into memory. You can use it to do some one-time initialization. PL/SQL Developer is not logged on yet and you can’t use the callback functions, so you are limited in the things you can do. --]] function OnCreate() --Add your code here --ShowMessage("OnCreate is called in lua script.") end --[[ Delphi procedure OnActivate OnActivate gets called after OnCreate. However, when OnActivate is called PL/SQL Developer and the Plug-In are fully initialized. This function is also called when the Plug-In is enabled in the configuration dialog. A good point to enable/disable menus. --]] function OnActivate() --Add your code here --ShowMessage("OnActivate is called in lua script.") --Add Truncate popup menu IDE_CreatePopupItem(plugInID,MENU_DDL_TRUCATE,"Truncate",OBJECT_TYPE_TABLE) IDE_CreatePopupItem(plugInID,MENU_UTL_PMSMETA,"PMS metadata",OBJECT_TYPE_TABLE) IDE_CreatePopupItem(plugInID,MENU_DDL_TABSRC_EXP,"Save DDL as",OBJECT_TYPE_TABLE) IDE_CreatePopupItem(plugInID,MENU_DML_TABREC_EXP,"Save records as",OBJECT_TYPE_TABLE) IDE_CreatePopupItem(plugInID,MENU_UTL_TAB_EXP,"Save table as",OBJECT_TYPE_TABLE) --Save source as IDE_CreatePopupItem(plugInID,MENU_UTL_SAVESRC,"Save source as",OBJECT_TYPE_PROCEDURE) IDE_CreatePopupItem(plugInID,MENU_UTL_SAVESRC,"Save source as",OBJECT_TYPE_FUNCTION) IDE_CreatePopupItem(plugInID,MENU_UTL_SAVESRC,"Save source as",OBJECT_TYPE_VIEW) IDE_CreatePopupItem(plugInID,MENU_UTL_SAVESRC,"Save source as",OBJECT_TYPE_PACKAGE) --Backup table data IDE_CreatePopupItem(plugInID,MENU_UTL_TAB_BAK,"Backup table data",OBJECT_TYPE_TABLE) end --[[ Delphi procedure OnDeactivate This is the counterpart of the OnActivate. It is called when the Plug-In is de-activated in the configuration dialog. --]] function OnDeactivate() --Add your code here --ShowMessage("OnDeactivate is called in lua script.") end --[[ Delphi procedure OnDestroy This is the counterpart of the OnCreate. You can dispose of anything you created in the OnCreate. --]] function OnDestroy() --Add your code here --ShowMessage("OnDestroy is called in lua script.") end --[[ Delphi function CanClose: Bool This will be called when PL/SQL Developer is about to close. If your PlugIn is not ready to close, you can show a message and return False. --]] function CanClose() --Add your code here --ShowMessage("CanClose is called in lua script.") return true end --[[ Delphi procedure AfterStart Called after all Plug-Ins are loaded and PL/SQL Developer is finished starting. --]] function AfterStart() --Add your code here --ShowMessage("AfterStart is called in lua script.") end --[[ Delphi procedure OnBrowserChange If your Plug-In depends on a selected item in the Browser, you can use this function to enable/disable menu-items. This function is called on every change in the Browser. You can use the IDE_GetBrowserInfo callback function to determine if the selected item is of interest to you. --]] function OnBrowserChange() --Add your code here --ShowMessage("OnBrowserChange is called in lua script.") end --[[ Delphi procedure OnWindowChange This function is called if PL/SQL Developer child windows change focus. You can use the IDE_GetWindowType callback to determine the active child window type. --]] function OnWindowChange() --Add your code here --ShowMessage("OnWindowChange is called in lua script.") end --[[ Delphi procedure OnWindowCreate(WindowType: Integer) This function is called directly after a new window is created. --]] function OnWindowCreate(WindowType) --Add your code here --ShowMessage("OnWindowCreate is called in lua script.") end --[[ Delphi procedure OnWindowCreated(WindowType: Integer) This function is called after a new window is created. The difference with the “Create” function is that the Window is now completely initialized. --]] function OnWindowCreated(WindowType) --Add your code here --ShowMessage("OnWindowCreated is called in lua script.") end --[[ Delphi function OnWindowClose(WindowType: Integer; Changed: BOOL): Integer This function allows you to take some action before a window is closed. You can influence the closing of the window with the following return values: 0 = Default behavior 1 = Ask the user for confirmation (like the contents was changed) 2 = Don’t ask, allow to close without confirmation The Changed Boolean indicates the current status of the window. --]] function OnWindowClose(WindowType,Changed) --Add your code here --ShowMessage("OnWindowClose is called in lua script.") return 0 end --[[ Delphi function BeforeExecuteWindow(WindowType: Integer): Bool This function is called before a Window is executed. Nothing is actually executed yet, and you can cancel execution by returning false. When you do return false, please give some feedback to the user why execution was cancelled. --]] function BeforeExecuteWindowe(WindowType) --Add your code here --ShowMessage("BeforeExecuteWindowe is called in lua script.") return true end --[[ Delphi procedure AfterExecuteWindow(WindowType, Result: Integer) When execution is finished, this function is called. The return parameter will indicate how execution finished: 0 = Finished with error 1 = Finished with the option to continue (like “next page” in the SQL Window) 2 = Finished successfully --]] function AfterExecuteWindow(WindowType,Result) --Add your code here --ShowMessage("AfterExecuteWindow is called in lua script.") end --[[ Delphi procedure OnConnectionChange This function is called when the user logs on to a different database or logs off. You can use the IDE_Connected and IDE_GetConnectionInfo callback to get information about the current connection. --]] function OnConnectionChange() --Add your code here --ShowMessage("OnConnectionChange is called in lua script.") end --[[ Delphi procedure OnPopup(ObjectType, ObjectName: PChar) This function is called when a context sensitive popup is about to be displayed. It gives you the opportunity to do something with the menus you have created with the IDE_CreatePopupMenuItem callback. --]] function OnPopup(ObjectType,ObjectName) --Add your code here --ShowMessage("OnPopup is called in lua script.") end --[[ Delphi procedure OnMainMenu(MenuName: PChar) This function is called when a main menu is selected (when it drops down). You can use this event to activate your Plug-In menu(s) if none of the other events are appropriate. The MenuName parameter is the name of the main menu item that was selected. --]] function OnMainMenu(MenuName) --Add your code here --ShowMessage("OnMainMenu is called in lua script.") end --[[ Delphi function OnTemplate(Filename: PChar; var Data: PChar): Bool This function is called before a template is executed. This gives you a chance to modify the contents in the Data parameter. If you return false, the template is cancelled. --]] function OnTemplate(Filename,Data) --Add your code here --ShowMessage("OnTemplate is called in lua script.") return true,Data end --[[ Delphi procedure OnFileLoaded(WindowType, Mode: Integer) Called after a file is loaded. The mode parameter can identify the following: 1: recovery file (from a crash) 2: backup file (normal file backup with a ~ extension) --]] function OnFileLoaded(WindowType,Mode) --Add your code here --ShowMessage("OnFileLoaded is called in lua script.") end --[[ Delphi procedure OnFileSaved(WindowType, Mode: Integer) Called after a file is saved. The mode parameter can identify the following: 1: recovery file (from a crash) 2: backup file (normal file backup with a ~ extension) --]] function OnFileSaved(WindowType,Mode) --Add your code here --ShowMessage("OnFileSaved is called in lua script.") end --[[ Delphi function About: PChar This function allows you to display an about dialog. You can decide to display a dialog yourself (in which case you should return an empty text) or just return the about text. In PL/SQL Developer 3.1 there is an about button in the Plug-In configuration dialog. --]] function About() --Add your code here --ShowMessage("About is called in lua script.") return "Yet Another Plug-In\nTBI Project Department\nYundian Tongfang Technology Co. Ltd." end --[[ Delphi procedure Configure If the Plug-In has a configure dialog you could use this function to activate it. This will allow a user to configure your Plug-In using the configure button in the Plug-In configuration dialog. --]] function Configure() --Add your code here --ShowMessage("Configure is called in lua script.") end --[[ Delphi procedure CommandLine(FeedbackHandle: Integer; Command, Params: PChar) You can use this function if you want the Plug-In to be able to accept commands from the command window. See IDE_CommandFeedback for how to return messages to the command window. --]] function CommandLine(FeedbackHandle,Command,Params) --Add your code here --ShowMessage("CommandLine is called in lua script.") end --[[ Delphi function PlugInName: PChar The PlugIn name (if defined) will be used for online updates, and as name for command window PlugIn commands. If you want your PlugIn to be handled by online updates, please contact support. If this function is not defined, the PlugInName will be the dll filename. --]] function PlugInName() --Add your code here --ShowMessage("PlugInName is called in lua script.") return "Yet Another Plug-In" end --[[ Delphi function PlugInSubName: PChar The subname will be added to the PlugInName. Possible values are ‘Trial’ or ‘Beta’. --]] function PlugInSubName() --Add your code here --ShowMessage("PlugInSubName is called in lua script.") return " Development Edition" end --[[ Delphi function PlugInShortName: PChar The short name is specifically for command window PlugIn commands. This allows you to specify a name that can be entered quickly. --]] function PlugInShortName() --Add your code here --ShowMessage("PlugInShortName is called in lua script.") return "Yap" end --[[ Delphi function RegisterFileSystem: PChar Use this function if you want your Plug-In to load/save files somewhere ‘external’. If you use this function you should return a description that identifies your filesystem (like FTP for the FTP Plug-in). See the chapter about External File Systems. --]] function RegisterFileSystem() --Add your code here --ShowMessage("RegisterFileSystem is called in lua script.") return "TFTP" end --[[ Delphi function DirectFileLoad: function(var Tag, Filename: PChar;WindowType: Integer): PChar This function will get called when a file will be directly loaded without a file dialog. This is needed if a user selects a file from the recent used files list. The Parameters indicate the file that you have to load and the return value is the file data. --]] function DirectFileLoad() --Add your code here --ShowMessage("DirectFileLoad is called in lua script.") return nil end --[[ Delphi function DirectFileSave(var Tag, Filename: PChar; Data: PChar;WindowType: Integer): Bool This function will be called when ‘File Save’ is selected (not ‘File Save As…). You should save the data as specified in the parameters and return True if everything was successful. --]] function DirectFileSave() --Add your code here --ShowMessage("DirectFileSave is called in lua script.") return true end --[[ Delphi function RegisterExport: PChar Use this function if you want to add an export option for (result) grids. The name you return will be the name that is displayed in the popup menus (next to html, xml, …). See the chapter about adding export options. --]] function RegisterExport() --Add your code here --ShowMessage("RegisterExport is called in lua script.") return nil end --[[ Delphi function ExportInit: Boolean First call after an export request. You can ask the user for a filename and/or initialize variables. Return False if you want to cancel the export. --]] function ExportInit() --Add your code here --ShowMessage("ExportInit is called in lua script.") return true end --[[ Delphi procedure ExportFinished;The export has finished. --]] function ExportFinished() --Add your code here --ShowMessage("ExportFinished is called in lua script.") end --[[ Delphi function ExportPrepare: Boolean This function allows you to prepare for the actual data. All values received with Exportdata before this function is called are column headers, and all values received after ExportPrepare is data. The return value allows you to signal if the prepare was processed correctly. --]] function ExportPrepare() --Add your code here --ShowMessage("ExportPrepare is called in lua script.") return true end --[[ Delphi function ExportData(Value: PChar): Boolean One cell of data, this can be the column description or the actual data. --]] function ExportData(Value) --Add your code here --ShowMessage("ExportData is called in lua script.") return true end --[[ ------------------------------------------------------------- Put other function below ------------------------------------------------------------- --]] --Another useful example is how to trim a string function trim (s) return (string.gsub(s, "^%s*(.-)%s*{1}quot;, "%1")) end --Write PMS Meta File function WirtePMSMeta(objectOwner,objectName,fd) SQL_ClearVariables() IDE_SplashCreate(100) IDE_SplashWriteLn("Generate PMS Metadata") local outLine="B\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Start") IDE_SplashProgress(5) --Get table header sqlStr="select a.table_name, b.comments from all_all_tables a, all_tab_comments b where a.owner = b.owner and a.table_name = b.table_name and a.owner = '"..objectOwner.."' and a.table_name = '"..objectName.."'" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else outLine=string.format("T %-20s%-20s%-51s\n",SQL_Field(SQL_FieldIndex("TABLE_NAME")),SQL_Field(SQL_FieldIndex("COMMENTS")), "不分块") end fd:write(outLine) fd:flush() IDE_SplashWriteLn("Table name is created") IDE_SplashProgress(10) SQL_ClearVariables() --Get column information sqlStr="select a.column_name, decode(a.data_type, 'NUMBER', 'NUMBER', 'CHAR', 'VARCHAR2', 'VARCHAR', 'VARCHAR2', a.data_type) data_type, a.data_length, a.data_precision, a.data_scale, a.nullable, a.data_default, b.comments from all_tab_columns a, all_col_comments b where a.owner = b.owner and a.table_name = b.table_name and a.column_name = b.column_name and a.owner = '" ..objectOwner.."' and a.table_name = '"..objectName.."' order by a.column_id" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else while SQL_Eof() == false do columnName = SQL_Field(SQL_FieldIndex("COLUMN_NAME")) dataType = SQL_Field(SQL_FieldIndex("DATA_TYPE")) dataLength = SQL_Field(SQL_FieldIndex("DATA_LENGTH")) dataPrecision = SQL_Field(SQL_FieldIndex("DATA_PRECISION")) dataScale = SQL_Field(SQL_FieldIndex("DATA_SCALE")) nullable = SQL_Field(SQL_FieldIndex("NULLABLE")) dataDefault = SQL_Field(SQL_FieldIndex("DATA_DEFAULT")) comment = SQL_Field(SQL_FieldIndex("COMMENTS")) combin="" if dataType=="VARCHAR2" then combin = dataType .. "(" .. dataLength .. ")" else if string.len(dataPrecision) == 0 or tonumber(dataPrecision) == 0 then dataPrecision = tostring("22") end if string.len(dataScale) == nil or string.len(dataScale) == 0 or tonumber(dataScale) == 0 then combin = dataType .. "(" .. dataPrecision .. ")" else combin = dataType .. "(" .. dataPrecision .. "," .. dataScale .. ")" end end if nullable== "N" then nullable = "NOT NULL" else nullable = "" end outLine = string.format("C %-20s%-20s%-15s%-15s%s\n", columnName, string.lower(combin), nullable, trim(dataDefault), trim(comment)) fd:write(outLine) fd:flush() SQL_Next() end IDE_SplashWriteLn("Columns is created") IDE_SplashProgress(80) SQL_ClearVariables() --Get primary key sqlStr="select a.constraint_name, b.column_name from all_constraints a, all_ind_columns b where a.owner = b.index_owner and a.table_name = b.table_name and a.index_name = b.index_name and a.constraint_type = 'P' and a.owner = '"..objectOwner.."' and a.table_name = '"..objectName.."' order by b.column_position" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else keyName="" keyColumns = "" while SQL_Eof() == false do keyName = SQL_Field(SQL_FieldIndex("CONSTRAINT_NAME")) keyColumns = keyColumns .. SQL_Field(SQL_FieldIndex("COLUMN_NAME")).. "," SQL_Next() end if string.len(keyColumns) > 0 then keyColumns=string.sub(keyColumns, 1, -2) primary="Primary" outLine = string.format("K %-20s%-20s%s\n", keyName, primary,keyColumns) fd:write(outLine) fd:flush() IDE_SplashWriteLn("Primary key is created") IDE_SplashProgress(90) end end SQL_ClearVariables() sqlStr="select t.index_name, t.index_type from all_indexes t where owner = '"..objectOwner.."' and table_name = '"..objectName.."' and not exists (select * from all_constraints where owner = t.owner and table_name = t.table_name and constraint_type = 'P' and index_name = t.index_name) order by index_name" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else ids={} for i = 0, 9 do --ids[i].flag = 0 ids[i]={["flag"] = 0,["indexName"] = "",["indexType"] = ""} end i = 0 while SQL_Eof() == false do ids[i].flag = 1 ids[i].indexName = SQL_Field(SQL_FieldIndex("INDEX_NAME")) ids[i].indexType = SQL_Field(SQL_FieldIndex("INDEX_TYPE")) i = i + 1 SQL_Next() end keyColumns = "" i = 0 while ids[i].flag == 1 do sqlStr="select t.column_name from all_ind_columns t where index_owner = '"..objectOwner.."' and table_name = '"..objectName.."' and index_name = '"..ids[i].indexName.."' and not exists (select * from all_constraints where owner = t.index_owner and table_name = t.table_name and constraint_type = 'P' and index_name = t.index_name) order by index_name, column_position" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else keyColumns = "" while SQL_Eof() == false do keyColumns = keyColumns .. SQL_Field(SQL_FieldIndex("COLUMN_NAME")).."," SQL_Next() end if string.len(keyColumns) > 0 then keyColumns=string.sub(keyColumns, 1, -2) outLine = string.format("I %-20s%-20s%s\n", ids[i].indexName, string.upper(string.sub(ids[i].indexType, 1,1)) .. string.lower(string.sub(ids[i].indexType,2,-1)), keyColumns) fd:write(outLine) fd:flush() IDE_SplashWriteLn("Index is created") IDE_SplashProgress(95) end end i = i + 1 end end SQL_ClearVariables() end outLine="D\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Completed") IDE_SplashProgress(100) IDE_SplashHide() return fd end --Export simple table DDL statement function ExportTableSimpleDDL(objectOwner,objectName,fd) SQL_ClearVariables() IDE_SplashCreate(100) IDE_SplashWriteLn("Save table "..string.upper(objectOwner.."."..objectName).." simple DDL") IDE_SplashProgress(5) sqlStr="select * from all_tab_comments where owner='"..string.upper(objectOwner).."' and table_name='"..string.upper(objectName).."'" tableComment="" outLine="" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else tableComment=SQL_Field(SQL_FieldIndex("COMMENTS")) end SQL_ClearVariables() outLine="/*Create table "..objectOwner.."."..objectName.."*/\n" fd:write(outLine) fd:flush() outLine="CREATE TABLE "..string.upper(objectOwner).."."..string.upper(objectName).." (--"..tableComment.."\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Table name is created") IDE_SplashProgress(10) sqlStr="select c.*,m.comments from all_tab_columns c,all_col_comments m where c.owner=m.owner and c.table_name=m.table_name and c.column_name=m.column_name and c.owner='"..string.upper(objectOwner).."' and c.table_name='"..string.upper(objectName).."' order by c.column_id" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else --Columns outLine="" repeat fd:write(outLine) fd:flush() columnName = SQL_Field(SQL_FieldIndex("COLUMN_NAME")) dataType = SQL_Field(SQL_FieldIndex("DATA_TYPE")) dataLength = SQL_Field(SQL_FieldIndex("DATA_LENGTH")) dataPrecision = SQL_Field(SQL_FieldIndex("DATA_PRECISION")) dataScale = SQL_Field(SQL_FieldIndex("DATA_SCALE")) nullable = SQL_Field(SQL_FieldIndex("NULLABLE")) dataDefault = SQL_Field(SQL_FieldIndex("DATA_DEFAULT")) comment = SQL_Field(SQL_FieldIndex("COMMENTS")) combin="" if dataType=="VARCHAR2" then combin = dataType .. "(" .. dataLength .. ")" else if string.len(dataPrecision) == 0 or tonumber(dataPrecision) == 0 then dataPrecision = tostring("22") end if string.len(dataScale) == nil or string.len(dataScale) == 0 or tonumber(dataScale) == 0 then combin = dataType .. "(" .. dataPrecision .. ")" else combin = dataType .. "(" .. dataPrecision .. "," .. dataScale .. ")" end end if nullable== "N" then nullable = "NOT NULL" else nullable = "" end SQL_Next() if dataDefault~=nil and string.len(trim(dataDefault)) ~= 0 then dataDefault="DEFAULT "..dataDefault end if SQL_Eof() == true then outLine = string.format("\t%s\t%s\t%s\t%s\t--%s\n", string.upper(columnName),string.upper(combin), trim(dataDefault),string.upper(nullable), trim(comment)) else outLine = string.format("\t%s\t%s\t%s\t%s,\t--%s\n", string.upper(columnName),string.upper(combin), trim(dataDefault),string.upper(nullable), trim(comment)) end until SQL_Eof() == true fd:write(outLine) fd:flush() outLine=");\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Columns information is created") IDE_SplashProgress(70) SQL_ClearVariables() sqlStr="select a.constraint_name, b.column_name from all_constraints a, all_ind_columns b where a.owner = b.index_owner and a.table_name = b.table_name and a.index_name = b.index_name and a.constraint_type = 'P' and a.owner = '"..string.upper(objectOwner).."' and a.table_name = '"..string.upper(objectName).."' order by b.column_position" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else --Primary Key keyName="" keyColumns = "" while SQL_Eof() == false do keyName = SQL_Field(SQL_FieldIndex("CONSTRAINT_NAME")) keyColumns = keyColumns .. SQL_Field(SQL_FieldIndex("COLUMN_NAME")).. "," SQL_Next() end if string.len(keyColumns) > 0 then keyColumns=string.sub(keyColumns, 1, -2) primary="Primary" outLine="/*Create Primary Key*/\n" fd:write(outLine) fd:flush() outLine = "ALTER TABLE "..string.upper(objectOwner.."."..objectName).." ADD CONSTRAINT "..string.upper(keyName).." PRIMARY KEY ("..string.upper(keyColumns)..");\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Primary key is created") IDE_SplashProgress(80) end end SQL_ClearVariables() sqlStr="select t.index_name, t.index_type from all_indexes t where owner = '"..string.upper(objectOwner).."' and table_name = '"..string.upper(objectName).."' and not exists (select * from all_constraints where owner = t.owner and table_name = t.table_name and constraint_type = 'P' and index_name = t.index_name) order by index_name" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else --Indexes ids={} for i = 0, 9 do --ids[i].flag = 0 ids[i]={["flag"] = 0,["indexName"] = "",["indexType"] = ""} end i = 0 while SQL_Eof() == false do ids[i].flag = 1 ids[i].indexName = SQL_Field(SQL_FieldIndex("INDEX_NAME")) ids[i].indexType = SQL_Field(SQL_FieldIndex("INDEX_TYPE")) i = i + 1 SQL_Next() end keyColumns = "" i = 0 while ids[i].flag == 1 do if i==0 then outLine="/*Create Index*/\n" fd:write(outLine) fd:flush() end sqlStr="select t.column_name from all_ind_columns t where index_owner = '"..string.upper(objectOwner).."' and table_name = '"..string.upper(objectName).."' and index_name = '"..ids[i].indexName.."' and not exists (select * from all_constraints where owner = t.index_owner and table_name = t.table_name and constraint_type = 'P' and index_name = t.index_name) order by index_name, column_position" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else keyColumns = "" while SQL_Eof() == false do keyColumns = keyColumns .. SQL_Field(SQL_FieldIndex("COLUMN_NAME")).."," SQL_Next() end if string.len(keyColumns) > 0 then keyColumns=string.sub(keyColumns, 1, -2) if string.upper(ids[i].indexType) == "NORMAL" then ids[i].indexType="" end outLine = "CREATE "..string.upper(ids[i].indexType).." INDEX "..ids[i].indexName.." ON "..objectOwner.."."..objectName.."("..keyColumns..");\n" fd:write(outLine) fd:flush() end end i = i + 1 end IDE_SplashWriteLn("Index is created") IDE_SplashProgress(85) end end --Table comment outLine = "/*Table comment*/\n" fd:write(outLine) fd:flush() outLine = "COMMENT ON TABLE "..string.upper(objectOwner.."."..objectName).." IS '"..tableComment.."';\n" fd:write(outLine) fd:flush() IDE_SplashWriteLn("Table comment is created") IDE_SplashProgress(90) --Column comments SQL_ClearVariables() outLine = "/*Table column comment*/\n" fd:write(outLine) fd:flush() sqlStr="select c.*,m.comments from all_tab_columns c,all_col_comments m where c.owner=m.owner and c.table_name=m.table_name and c.column_name=m.column_name and c.owner='"..string.upper(objectOwner).."' and c.table_name='"..string.upper(objectName).."' order by c.column_id" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else while SQL_Eof() == false do columnName = SQL_Field(SQL_FieldIndex("COLUMN_NAME")) comment = SQL_Field(SQL_FieldIndex("COMMENTS")) outLine = "COMMENT ON COLUMN "..string.upper(objectOwner.."."..objectName).."."..columnName.." IS '"..comment.."';\n" fd:write(outLine) fd:flush() SQL_Next() end end IDE_SplashWriteLn("Column comment is created") IDE_SplashProgress(95) IDE_SplashWriteLn("Completed") IDE_SplashProgress(100) IDE_SplashHide() return fd end --Export table records function ExportTableRecords(objectOwner,objectName,fd) SQL_ClearVariables() IDE_SplashCreate(100) IDE_SplashWriteLn("Write table records") --Query table column meta sqlStr="select * from all_tab_columns where owner='"..string.upper(objectOwner).."' and table_name='"..string.upper(objectName).."' order by column_id" if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else i=1 rows={} --Fix in lua table while SQL_Eof() == false do col={["USED"]=1,["COLUMN_NAME"]="",["DATA_TYPE"]="",["COLUMN_VALUE"]=""} col.COLUMN_NAME=SQL_Field(SQL_FieldIndex("COLUMN_NAME")) col.DATA_TYPE=SQL_Field(SQL_FieldIndex("DATA_TYPE")) rows[i]=col SQL_Next() i=i+1 end --End flag element col={["USED"]=0,["COLUMN_NAME"]="",["DATA_TYPE"]="",["COLUMN_VALUE"]=""} rows[i]=col SQL_ClearVariables() IDE_SplashWriteLn("Table column meta created") IDE_SplashProgress(1) instStr="INSERT INTO "..string.upper(objectOwner).."."..string.upper(objectName).."(" i=1 --Fix insert statement while rows[i].USED==1 do instStr=instStr..rows[i].COLUMN_NAME if rows[i+1].USED ~= 0 then instStr=instStr.."," end i=i+1 end IDE_SplashWriteLn("Insert statement skeleton created") IDE_SplashProgress(2) instStr=instStr..") VALUES(" sqlStr="select count(*) rowcount from "..string.upper(objectOwner).."."..string.upper(objectName) rowCount=0 currentRow=0 --Get row count if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else rowCount=tonumber(SQL_Field(SQL_FieldIndex("ROWCOUNT"))) end SQL_ClearVariables() IDE_SplashWriteLn("Table column meta created") IDE_SplashProgress(3) --Query table data sqlStr="select * from "..string.upper(objectOwner).."."..string.upper(objectName) if SQL_Execute(sqlStr) ~= 0 then ShowMessage("Could not execute query to fetch table infomation!") return nil else IDE_SplashWriteLn("Write record data as insert statement...") fd:write("--Insert table data\n") fd:flush() insertHead=instStr while SQL_Eof() == false do instStr=insertHead i=1 --Fix data part while rows[i].USED==1 do if rows[i].DATA_TYPE == "VARCHAR2" or rows[i].DATA_TYPE == "NVARCHAR2" or rows[i].DATA_TYPE == "CHAR" then instStr=instStr.."'"..SQL_Field(SQL_FieldIndex(rows[i].COLUMN_NAME)).."'" else instStr=instStr..SQL_Field(SQL_FieldIndex(rows[i].COLUMN_NAME)) end if rows[i+1].USED ~= 0 then instStr=instStr.."," end i=i+1 end instStr=instStr..");\n" --Write insert statement line fd:write(instStr) fd:flush() SQL_Next() currentRow=currentRow+1 IDE_SplashProgress(currentRow/rowCount*100) end end end SQL_ClearVariables() IDE_SplashProgress(100) IDE_SplashHide() return fd end
函数指针定义。
/* Function pointer for IDE utilities */ /* FUNC:1 */ int(*SYS_Version)(); /* FUNC:2 */ char* (*SYS_Registry)(); /* FUNC:3 */ char* (*SYS_RootDir)(); /* FUNC:4 */ char* (*SYS_OracleHome)(); /* FUNC:5 */ char* (*SYS_OCIDLL)(); /* FUNC:6 */ BOOL* (*SYS_OCI8Mode)(); /* FUNC:7 */ BOOL* (*SYS_XPStyle)(); /* FUNC:8 */ char* (*SYS_TNSNAMES)(char*Param); /* FUNC:9 */ int(*SYS_DelphiVersion)(); /* FUNC:10 */ void(*IDE_MenuState)(int ID, int Index, BOOL Enabled); /* FUNC:11 */ BOOL(*IDE_Connected)(); /* FUNC:12 */ void(*IDE_GetConnectionInfo)(char**Username, char**Password, char**Database); /* FUNC:13 */ void(*IDE_GetBrowserInfo)(char**ObjectType, char**ObjectOwner, char**ObjectName); /* FUNC:14 */ int(*IDE_GetWindowType)(); /* FUNC:15 */ int(*IDE_GetAppHandle)(); /* FUNC:16 */ int(*IDE_GetWindowHandle)(); /* FUNC:17 */ int(*IDE_GetClientHandle)(); /* FUNC:18 */ int(*IDE_GetChildHandle)(); /* FUNC:19 */ void(*IDE_Refresh)(); /* FUNC:20 */ void(*IDE_CreateWindow)(int WindowType, char*Text, BOOL Execute); /* FUNC:21 */ BOOL(*IDE_OpenFile)(int WindowType, char*Filename); /* FUNC:22 */ BOOL(*IDE_SaveFile)(); /* FUNC:23 */ char* (*IDE_Filename)(); /* FUNC:24 */ void(*IDE_CloseFile)(); /* FUNC:25 */ void(*IDE_SetReadOnly)(BOOL ReadOnly); /* FUNC:26 */ BOOL(*IDE_GetReadOnly)(); /* FUNC:27 */ BOOL(*IDE_ExecuteSQLReport)(char*SQL, char*Title, BOOL Updateable); /* FUNC:28 */ BOOL(*IDE_ReloadFile)(); /* FUNC:29 */ void(*IDE_SetFilename)(char*Filename); /* FUNC:30 */ char* (*IDE_GetText)(); /* FUNC:31 */ char* (*IDE_GetSelectedText)(); /* FUNC:32 */ char* (*IDE_GetCursorWord)(); /* FUNC:33 */ int(*IDE_GetEditorHandle)(); /* FUNC:34 */ BOOL(*IDE_SetText)(char*Text); /* FUNC:35 */ BOOL(*IDE_SetStatusMessage)(char*Text); /* FUNC:36 */ BOOL(*IDE_SetErrorPosition)(int Line, int Col); /* FUNC:37 */ void(*IDE_ClearErrorPositions)(); /* FUNC:38 */ int(*IDE_GetCursorWordPosition)(); /* FUNC:39 */ BOOL(*IDE_Perform)(int Param); /* FUNC:40 */ int(*SQL_Execute)(char*SQL); /* FUNC:41 */ int(*SQL_FieldCount)(); /* FUNC:42 */ BOOL(*SQL_Eof)(); /* FUNC:43 */ int(*SQL_Next)(); /* FUNC:44 */ char* (*SQL_Field)(int Field); /* FUNC:45 */ char* (*SQL_FieldName)(int Field); /* FUNC:46 */ int(*SQL_FieldIndex)(char*Name); /* FUNC:47 */ int(*SQL_FieldType)(int Field); /* FUNC:48 */ char* (*SQL_ErrorMessage)(); /* FUNC:50 */ BOOL(*SQL_UsePlugInSession)(int PlugInID); /* FUNC:51 */ void(*SQL_UseDefaultSession)(int PlugInID); /* FUNC:52 */ BOOL(*SQL_CheckConnection)(); /* FUNC:53 */ char* (*SQL_GetDBMSGetOutput)(); /* FUNC:54 */ void(*SQL_SetVariable)(char*Name, char*Value); /* FUNC:55 */ char* (*SQL_GetVariable)(char*Name); /* FUNC:56 */ void(*SQL_ClearVariables)(); /* FUNC:60 */ char* (*IDE_GetCustomKeywords)(); /* FUNC:61 */ void(*IDE_SetCustomKeywords)(char*Keywords); /* FUNC:62 */ void(*IDE_SetKeywords)(int ID, int Style, char*Keywords); /* FUNC:63 */ void(*IDE_ActivateKeywords)(); /* FUNC:64 */ void(*IDE_RefreshMenus)(int ID); /* FUNC:65 */ void(*IDE_SetMenuName)(int ID, int Index, char*Name); /* FUNC:66 */ void(*IDE_SetMenuCheck)(int ID, int Index, BOOL Enabled); /* FUNC:67 */ void(*IDE_SetMenuVisible)(int ID, int Index, BOOL Enabled); /* FUNC:68 */ char* (*IDE_GetMenulayout)(); /* FUNC:69 */ void* (*IDE_CreatePopupItem)(int ID, int Index, char*Name, char*ObjectType); /* FUNC:70 */ BOOL(*IDE_SetConnection)(char*Username, char*Password, char*Database); /* FUNC:71 */ int(*IDE_GetObjectInfo)(char*AnObject, char**ObjectType, char**ObjectOwner, char**ObjectName, char**SubObject); /* FUNC:72 */ char* (*IDE_GetBrowserItems)(char*Node, BOOL GetItems); /* FUNC:73 */ void(*IDE_RefreshBrowser)(char*Node); /* FUNC:74 */ int(*IDE_GetPopupObject)(char**ObjectType, char**ObjectOwner, char**ObjectName, char**SubObject); /* FUNC:75 */ char* (*IDE_GetPopupBrowserRoot)(); /* FUNC:76 */ void(*IDE_RefreshObject)(char*ObjectType, char*ObjectOwner, char*ObjectName, int Action); /* FUNC:77 */ BOOL(*IDE_FirstSelectedObject)(char*ObjectType, char*ObjectOwner, char*ObjectName, char*SubObject); /* FUNC:78 */ BOOL(*IDE_NextSelectedObject)(char*ObjectType, char*ObjectOwner, char*ObjectName, char*SubObject); /* FUNC:79 */ char* (*IDE_GetObjectSource)(char*ObjectType, char*ObjectOwner, char*ObjectName); /* FUNC:80 */ int(*IDE_GetWindowCount)(); /* FUNC:81 */ BOOL(*IDE_SelectWindow)(int Index); /* FUNC:82 */ BOOL(*IDE_ActivateWindow)(int Index); /* FUNC:83 */ BOOL(*IDE_WindowIsModified)(); /* FUNC:84 */ BOOL(*IDE_WindowIsRunning)(); /* FUNC:90 */ void(*IDE_SplashCreate)(int ProgressMax); /* FUNC:91 */ void(*IDE_SplashHide)(); /* FUNC:92 */ void(*IDE_SplashWrite)(char*s); /* FUNC:93 */ void(*IDE_SplashWriteLn)(char*s); /* FUNC:94 */ void(*IDE_SplashProgress)(int Progress); /* FUNC:95 */ char* (*IDE_TemplatePath)(); /* FUNC:96 */ BOOL(*IDE_ExecuteTemplate)(char*Template, BOOL NewWindow); /* FUNC:97 */ char*(*IDE_GetConnectAs)(); /* FUNC:98 */ BOOL(*IDE_SetConnectionAs)(char*Username, char*Password, char*Database, char*ConnectAs); /* FUNC:100 */ char* (*IDE_GetFileOpenMenu)(int MenuIndex, int*WindowType); /* FUNC:101 */ BOOL(*IDE_CanSaveWindow)(); /* FUNC:102 */ void(*IDE_OpenFileExternal)(int WindowType, char*Data, char*FileSystem, char*Tag, char*Filename); /* FUNC:103 */ char* (*IDE_GetFileTypes)(int WindowType); /* FUNC:104 */ char* (*IDE_GetDefaultExtension)(int WindowType); /* FUNC:105 */ char* (*IDE_GetFiledata)(); /* FUNC:106 */ void(*IDE_FileSaved)(char*FileSystem, char*FileTag, char*Filename); /* FUNC:107 */ BOOL(*IDE_ShowHTML)(char*Url, char*Hash, char*Title, char*ID); /* FUNC:108 */ BOOL(*IDE_RefreshHTML)(char*Url, char*ID, BOOL BringToFront); /* FUNC:109 */ char* (*IDE_GetProcEditExtension)(char*oType); /* FUNC:110 */ BOOL(*IDE_GetWindowObject)(char**ObjectType, char**ObjectOwner, char**ObjectName, char**SubObject); /* FUNC:111 */ char* (*IDE_FirstSelectedFile)(BOOL Files, BOOL Directories); /* FUNC:112 */ char* (*IDE_NextSelectedFile)(); /* FUNC:113 */ void(*IDE_RefreshFileBrowser)(); /* FUNC:120 */ void(*IDE_KeyPress)(int Key, int Shift); /* FUNC:121 */ int(*IDE_GetMenuItem)(char*MenuName); /* FUNC:122 */ BOOL(*IDE_SelectMenu)(int MenuItem); /* FUNC:130 */ char* (*IDE_TranslationFile)(); /* FUNC:131 */ char* (*IDE_TranslationLanguage)(); /* FUNC:132 */ char* (*IDE_GetTranslatedMenuLayout)(); /* FUNC:133 */ char* (*IDE_MainFont)(); /* FUNC:134 */ char* (*IDE_TranslateItems)(char*Group); /* FUNC:135 */ char* (*IDE_TranslateString)(char*ID, char*Default, char Param1, char Param2); /* FUNC:140 */ BOOL(*IDE_SaveRecoveryFiles)(); /* FUNC:141 */ int(*IDE_GetCursorX)(); /* FUNC:142 */ int(*IDE_GetCursorY)(); /* FUNC:143 */ void(*IDE_SetCursor)(int X, int Y); /* FUNC:144 */ int(*IDE_SetBookmark)(int Index, int X, int Y); /* FUNC:145 */ void(*IDE_ClearBookmark)(int Index); /* FUNC:146 */ void(*IDE_GotoBookmark)(int Index); /* FUNC:147 */ BOOL(*IDE_GetBookmark)(int Index, int X, int Y); /* FUNC:148 */ char* (*IDE_TabInfo)(int Index); /* FUNC:149 */ int(*IDE_TabIndex)(int Index); /* FUNC:150 */ void(*IDE_CreateToolButton)(int ID, int Index, char*Name, char*BitmapFile, int BitmapHandle); /* FUNC:153 */ BOOL(*IDE_WindowHasEditor)(BOOL CodeEditor); /* FUNC:160 */ int(*IDE_BeautifierOptions)(); /* FUNC:161 */ BOOL(*IDE_BeautifyWindow)(); /* FUNC:162 */ char* (*IDE_BeautifyText)(char*S); /* FUNC:165 */ BOOL(*IDE_ObjectAction)(char*Action, char*ObjectType, char*ObjectOwner, char*ObjectName); /* FUNC:166 */ BOOL(*IDE_ShowDialog)(char*Dialog, char*Param); /* FUNC:173 */ void(*IDE_DebugLog)(char*Msg); /* FUNC:174 */ char* (*IDE_GetParamString)(char*Name); /* FUNC:175 */ BOOL(*IDE_GetParamBool)(char*Name); /* FUNC:176 */ void(*IDE_GetBrowserFilter)(int Index, char**Name, char**WhereClause, char**OrderByClause, char**User, BOOL Active); /* FUNC:180 */ void(*IDE_CommandFeedback)(int FeedbackHandle, char*S); /* FUNC:190 */ int(*IDE_ResultGridRowCount)(); /* FUNC:191 */ int(*IDE_ResultGridColCount)(); /* FUNC:192 */ char* (*IDE_ResultGridCell)(int Col, int Row); /* FUNC:200 */ BOOL(*IDE_Authorized)(char*Category, char*Name, char*SubName); /* FUNC:201 */ BOOL(*IDE_WindowAllowed)(int WindowType, BOOL ShowErrorMessage); /* FUNC:202 */ BOOL(*IDE_Authorization)(); /* FUNC:203 */ char* (*IDE_AuthorizationItems)(char*Category); /* FUNC:204 */ void(*IDE_AddAuthorizationItem)(int PlugInID, char*Name); /* FUNC:210 */ char* (*IDE_GetPersonalPrefSets)(); /* FUNC:211 */ char* (*IDE_GetDefaultPrefSets)(); /* FUNC:212 */ char* (*IDE_GetPrefAsString)(int PlugInID, char*PrefSet, char*Name, char*Default); /* FUNC:213 */ int(*IDE_GetPrefAsInteger)(int PlugInID, char*PrefSet, char*Name, BOOL Default); /* FUNC:214 */ BOOL(*IDE_GetPrefAsBool)(int PlugInID, char*PrefSet, char*Name, BOOL Default); /* FUNC:215 */ BOOL(*IDE_SetPrefAsString)(int PlugInID, char*PrefSet, char*Name, char*Value); /* FUNC:216 */ BOOL(*IDE_SetPrefAsInteger)(int PlugInID, char*PrefSet, char*Name, int Value); /* FUNC:217 */ BOOL(*IDE_SetPrefAsBool)(int PlugInID, char*PrefSet, char*Name, BOOL Value); /* FUNC:218 */ char* (*IDE_GetGeneralPref)(char*Name); /* FUNC:219 */ BOOL(*IDE_PlugInSetting)(int PlugInID, char*Setting, char*Value); /* FUNC:220 */ int(*IDE_GetProcOverloadCount)(char*Owner, char*PackageName, char*ProcedureName); /* FUNC:221 */ int(*IDE_SelectProcOverloading)(char*Owner, char*PackageName, char*ProcedureName); /* FUNC:230 */ char* (*IDE_GetSessionValue)(char*Name); /* FUNC:231 */ BOOL(*IDE_CheckDBVersion)(char*Version);几个工具函数。
/* Define unique plug-in ID */ int nPluginID = 0; /* Lua virtual machine */ lua_State *L = NULL; /* Save the Plugin ID for future use */ int SavePluginID(int nID) { nPluginID = nID; return nPluginID; } /* Clear Lua virtual machine support */ void ClearLuaSupport() { if (L) lua_close(L); } /* Help functions,register c function in order to lua use */ int RegisterRoutine(lua_State *l, const char *routine, lua_CF fp) { if (!l) return REGISTER_ROUTINE_ERROR; lua_pushstring(l, routine); lua_pushcfunction(L, fp); lua_settable(l, LUA_GLOBALSINDEX); return ANYTHING_IS_OK; } /* Help functions,show lua messages */ int luax_ShowMessage(lua_State *l) { #ifdef _DEBUG char *pszVar, msg[LUA_MESSAGE_SIZE]; int i, n; CHECK_LUA; n = lua_gettop(l); memset(msg, '\0', sizeof(msg)); for (i = 1; i <= n; ++i) { pszVar = (char*)lua_tostring(l, i); if (strlen(msg) + strlen(pszVar) >= LUA_MESSAGE_SIZE / sizeof(TCHAR)) break; else strcat(msg, pszVar); } MessageBox((HWND)GetDesktopWindow(), msg, "Lua Messages", MB_OK); #endif return 0; } /* Help functions,show messages and get options */ int luax_ShowMessageOption(lua_State *l) { char *pszVar, msg[LUA_MESSAGE_SIZE]; int i, n, retVal; CHECK_LUA; n = lua_gettop(l); memset(msg, '\0', sizeof(msg)); for (i = 1; i <= n; ++i) { pszVar = (char*)lua_tostring(l, i); if (strlen(msg) + strlen(pszVar) >= LUA_MESSAGE_SIZE / sizeof(TCHAR)) break; else strcat(msg, pszVar); } retVal = MessageBox((HWND)GetDesktopWindow(), msg, "Lua Messages", MB_YESNO); if (retVal == IDYES) { lua_pushnumber(l, 1); } else if (retVal == IDNO) { lua_pushnumber(l, 0); } else { lua_pushnumber(l, -1); } return 1; } /* Add a not enough but common dialog to fetch user data. */ #define ID_TEXT 250 #define ID_CONTENT 300 #define ID_OK 350 #define ID_CANCEL 400 char fetchMsg[1024]; /* Get windows error formatted messages and exit process */ void ErrorExit(LPTSTR lpszFunction) { LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) *sizeof(TCHAR)); wsprintf((LPTSTR)lpDisplayBuf, TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf); MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); ExitProcess(dw); } /* Do align */ static LPWORD LPWAlign(LPWORD lpIn) { ULONG ul; ULONG dw2Power = 4; ul = (ULONG)lpIn; ul += dw2Power - 1; ul &= ~(dw2Power - 1); return (LPWORD)ul; } #define lpwAlign LPWAlign /* Self define dialog procedure */ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc, rcDlg, rcOwner; HWND hwndOwner; HICON hIcon; switch (message) { case WM_INITDIALOG: // Get the owner window and dialog box rectangles. if ((hwndOwner = GetParent(hwndDlg)) == NULL) { hwndOwner = GetDesktopWindow(); } GetWindowRect(hwndOwner, &rcOwner); GetWindowRect(hwndDlg, &rcDlg); CopyRect(&rc, &rcOwner); // Offset the owner and dialog box rectangles so that right and bottom // values represent the width and height, and then offset the owner again // to discard space taken up by the dialog box. OffsetRect(&rcDlg, -rcDlg.left, -rcDlg.top); OffsetRect(&rc, -rc.left, -rc.top); OffsetRect(&rc, -rcDlg.right, -rcDlg.bottom); // The new position is the sum of half the remaining space and the owner's // original position. SetWindowPos(hwndDlg, HWND_TOP, rcOwner.left + (rc.right / 2), rcOwner.top + (rc.bottom / 2), 0, 0, // Ignores size arguments. SWP_NOSIZE); if (GetDlgCtrlID((HWND) wParam) != ID_CONTENT) { SetFocus(GetDlgItem(hwndDlg, ID_CONTENT)); return FALSE; } if (hIcon = LoadIcon(GetModuleHandle(NULL), IDI_APPLICATION)) { SetClassLong(hwndDlg, // window handle GCL_HICON, // changes icon (LONG) hIcon); return FALSE; } return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case ID_OK: GetDlgItemText(hwndDlg, ID_CONTENT, fetchMsg, sizeof(fetchMsg) / sizeof(TCHAR)); EndDialog(hwndDlg, ID_OK); return TRUE; case ID_CANCEL: EndDialog(hwndDlg, ID_CANCEL); return TRUE; } } return FALSE; } /* Show self define dialog box */ static LRESULT DisplayDialogBox(HINSTANCE hinst, HWND hwndOwner, LPSTR lpszTitle, LPSTR lpszDataCaption, LPSTR lpszDataDefault) { HGLOBAL hgbl; LPDLGTEMPLATE lpdt; LPDLGITEMTEMPLATE lpdit; LPWORD lpw; LPWSTR lpwsz, lpwszLeader, lpwszStub; LRESULT ret; int nchar; hgbl = GlobalAlloc(GMEM_ZEROINIT, 1024); if (!hgbl) return -1; lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl); // Define a dialog box. lpdt->style = WS_POPUP | WS_BORDER | WS_SYSMENU | DS_MODALFRAME | WS_CAPTION; lpdt->cdit = 4; // Number of controls lpdt->x = 10; lpdt->y = 10; lpdt->cx = 149; lpdt->cy = 99; lpw = (LPWORD)(lpdt + 1); *lpw++ = 0; // No menu *lpw++ = 0; // Predefined dialog box class (by default) /* Write dialog caption */ lpwsz = (LPWSTR)lpw; nchar = MultiByteToWideChar(CP_ACP, 0, lpszTitle, -1, lpwsz, 255); lpw += nchar; // ----------------------- // Define an OK button. // ----------------------- lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary lpdit = (LPDLGITEMTEMPLATE)lpw; lpdit->x = 21; lpdit->y = 77; lpdit->cx = 50; lpdit->cy = 14; lpdit->id = ID_OK; // OK button identifier lpdit->style = WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON; lpw = (LPWORD)(lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0080; // Button class lpwsz = (LPWSTR)lpw; nchar = MultiByteToWideChar(CP_ACP, 0, "OK", -1, lpwsz, 50); lpw += nchar; lpw = lpwAlign(lpw); // Align creation data on DWORD boundary *lpw++ = 0; // No creation data // ----------------------- // Define a Cancel button. // ----------------------- lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary lpdit = (LPDLGITEMTEMPLATE)lpw; lpdit->x = 81; lpdit->y = 77; lpdit->cx = 50; lpdit->cy = 14; lpdit->id = ID_CANCEL; // Help button identifier lpdit->style = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON; lpw = (LPWORD)(lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0080; // Button class atom lpwsz = (LPWSTR)lpw; nchar = MultiByteToWideChar(CP_ACP, 0, "Cancel", -1, lpwsz, 50); lpw += nchar; lpw = lpwAlign(lpw); // Align creation data on DWORD boundary *lpw++ = 0; // No creation data // ----------------------- // Define a Edit box. // ----------------------- lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary lpdit = (LPDLGITEMTEMPLATE)lpw; lpdit->x = 9; lpdit->y = 22; lpdit->cx = 133; lpdit->cy = 54; lpdit->id = ID_CONTENT; // Edit identifier lpdit->style = WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN; lpw = (LPWORD)(lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0081; // Edit class lpwsz = (LPWSTR)lpw; nchar = MultiByteToWideChar(CP_ACP, 0, lpszDataDefault, -1, lpwsz, 255); lpw += nchar; lpw = lpwAlign(lpw); // Align creation data on DWORD boundary *lpw++ = 0; // No creation data // ----------------------- // Define a static text control. // ----------------------- lpw = lpwAlign(lpw); // Align DLGITEMTEMPLATE on DWORD boundary lpdit = (LPDLGITEMTEMPLATE)lpw; lpdit->x = 7; lpdit->y = 7; lpdit->cx = 50; lpdit->cy = 12; lpdit->id = ID_TEXT; // Text identifier lpdit->style = WS_CHILD | WS_VISIBLE | SS_LEFT; lpw = (LPWORD)(lpdit + 1); *lpw++ = 0xFFFF; *lpw++ = 0x0082; // Static class lpwsz = (LPWSTR)lpw; nchar = MultiByteToWideChar(CP_ACP, 0, lpszDataCaption, -1, lpwsz, 255); lpw += nchar; lpw = lpwAlign(lpw); // Align creation data on DWORD boundary *lpw++ = 0; // No creation data /* */ GlobalUnlock(hgbl); ret = DialogBoxIndirectParam(hinst, (LPDLGTEMPLATE)hgbl, hwndOwner, (DLGPROC)DialogProc, NULL); // // ErrorExit("DisplayDialogBox"); // GlobalFree(hgbl); return ret; } /* Show self define dialog by lua */ int luax_FetchData(lua_State *l) { int ret; char *dlgCap, *datCap, *datDefault; if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } dlgCap = (char *)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } datCap = (char *)lua_tostring(l, 2); if (!lua_isstring(l, 3)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } datDefault = (char *)lua_tostring(l, 3); memset(fetchMsg, '\0', sizeof(fetchMsg)); ret = DisplayDialogBox(GetModuleHandle(NULL), (HWND)IDE_GetWindowHandle(), dlgCap, datCap, datDefault); lua_pushstring(l, fetchMsg); lua_pushnumber(l, ret); return 2; } /* Dumping stack information to given buffer */ static void Stack2Buff(lua_State *L, char *buff) { int i; char msg[LUA_MESSAGE_SIZE]; int top = lua_gettop(L); if (!buff) return; sprintf(buff, "-----BEGIN-----\n"); for (i = 1; i <= top; i++) { /* repeat for each level */ int t = lua_type(L, i); switch (t) { case LUA_TSTRING: { /* strings */ memset(msg, '\0', sizeof(LUA_MESSAGE_SIZE)); sprintf(msg, "[INDEX %d]'%s'\n", i, lua_tostring(L, i)); break; } case LUA_TBOOLEAN: { /* booleans */ memset(msg, '\0', sizeof(LUA_MESSAGE_SIZE)); sprintf(msg, "[INDEX %d]%s\n", i, lua_toboolean(L, i) ? "true" : "false"); break; } case LUA_TNUMBER: { /* numbers */ memset(msg, '\0', sizeof(LUA_MESSAGE_SIZE)); sprintf(msg, "[INDEX %d]%g\n", i, lua_tonumber(L, i)); break; } default: { /* other values */ memset(msg, '\0', sizeof(LUA_MESSAGE_SIZE)); sprintf(msg, "[INDEX %d]%s\n", i, lua_typename(L, t)); break; } } strcat(buff, msg); } strcat(buff, "-----END-----\n"); } /* Get open file name string */ int luax_GetOpenFileName(lua_State *l) { // Initialize OPENFILENAME BOOL bResult = FALSE; DWORD dwError = NOERROR; OPENFILENAME ofn = {0}; // Get lua parameters char *szFilter, *szFile; // buffer for filter and file name if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } szFilter = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } szFile = (char*)lua_tostring(l, 2); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner=IDE_GetWindowHandle(); ofn.lpstrTitle="Lua Open Files"; ofn.lpstrFilter = szFilter; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST; // Display the Open dialog box. bResult = GetOpenFileName(&ofn); if (bResult == FALSE) { dwError = CommDlgExtendedError(); lua_pushstring(l, ""); } else { lua_pushstring(l, ofn.lpstrFile); } return 1; } /* Get save as file name string */ int luax_GetSaveFileName(lua_State *l) { // Initialize OPENFILENAME BOOL bResult = FALSE; DWORD dwError = NOERROR; OPENFILENAME ofn = {0}; // Get lua parameters char *szFilter, *szFile; // buffer for filter and file name if (!lua_isstring(l, 1)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } szFilter = (char*)lua_tostring(l, 1); if (!lua_isstring(l, 2)) { lua_pushstring(l, "incorrect argument"); lua_error(l); } szFile = (char*)lua_tostring(l, 2); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner=IDE_GetWindowHandle(); ofn.lpstrTitle="Lua Save Files"; ofn.lpstrFilter = szFilter; ofn.lpstrFile = szFile; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT; // Display the Save dialog box. bResult = GetSaveFileName(&ofn); if (bResult == FALSE) { dwError = CommDlgExtendedError(); lua_pushstring(l, ""); } else { lua_pushstring(l, ofn.lpstrFile); } return 1; }