This problem occurs today when a C function is exposed to LUA.
The approximate code is this,
Header file:
#ifndef level_designer_h#define Level_designer_hextern "C" {#include "lualib.h" #include "tolua_fix.h"}static int SaveFileDialog (lua_state *tolus_s); static int OpenFileDialog (lua_state *tolus_s); int Open_windows_lua (Lua_State * tolus_s); #endif
Source file:
#include "LevelDesignerUtils.h" #include <afxwin.h>//MFC core components and standard components # include <afxext.h>//MFC Extension # include <afxdisp.h>//MFC Automation class//wchar to Charvoid tc2c (const PTCHAR TC, char * c) {#if defined (UNICODE) Wid Echartomultibyte (CP_ACP, 0, TC,-1, C, wcslen (TC), 0, 0); C[wcslen (TC)] = 0; #elselstrcpy ((PTSTR) c, (PTSTR) TC); #endif} static int OpenFileDialog (Lua_state *tolus_s) {//TODO: Add Command handler code here CFileDialog *dlg = new CFileDialog (true, NULL, NULL, of n_hidereadonly | Ofn_overwriteprompt, _t ("JSON file (*.json) |*.json| configuration file (*.dat) |*.dat| All Files (*. *) |*.*| |")); Nt_ptr nresponse = Dlg->domodal (); CString Filpath = ""; if (IDCANCEL = = nresponse) {delete dlg;} else if (IDOK = = nresponse) {Filpath = Dlg->getpathname ();d elete Dlg;} Char Filepathc[max_path]; TC2C (Filpath.getbuffer (), filepathc); Lua_pushstring (tolus_s, FILEPATHC); return 1;} static int SaveFileDialog (Lua_state *tolus_s) {CFileDialog *dlg = new CFileDialog (false, NULL, NULL, OFN_HIDEREADONLY | Ofn_overwriteprompt,_t ("JSON file (*.json) |*.json| configuration file (*.dat) |*.dat| All Files (*. *) |*.*| |")); Nt_ptr nresponse = Dlg->domodal (); CString Filpath = ""; if (IDCANCEL = = nresponse) {delete dlg;} else if (IDOK = = nresponse) {Filpath = Dlg->getpathname ();d elete Dlg;} Char Filepathc[max_path]; TC2C (Filpath.getbuffer (), filepathc); Lua_pushstring (tolus_s, FILEPATHC); return 1;} int Open_windows_lua (lua_state *tolus_s) {lua_register (tolus_s, "Win_openfiledialog", OpenFileDialog); Lua_register ( tolus_s, "Win_savefiledialog", SaveFileDialog); return 0;}
Later flip through, find out why:
A static function can only be seen in the file that declares it, cannot be called by other files, that is, a static function can only be called in a file that is known to it, and cannot be called in any other file.
Of course, it's completely unnecessary for me to declare the static function in the header file. After removal, it's ready.
Error c2129: static function declared but not defined