int main(int argc, char ** argv) { setExecutablePath(argv[0]); lua_State *L = lua_open(); luaL_openlibs(L); #if USE_IUP iuplua_open(L); cdlua_open(L); cdluaiup_open(L); iupkey_open(L); iupimlua_open(L); IupImageLibOpen (); iupcontrolslua_open(L); imlua_open(L); imlua_open_process(L); #endif luaopen_pack(L); luaopen_lfs(L); luaopen_marshal(L); luaopen_mime_core(L); luaopen_socket_core(L); pdfdoc_register(L); pdfpage_register(L); clipboard_register(L); luaopen_system(L); luaopen_compare(L); #if _DEBUG lua_pushboolean(L, true); lua_setfield(L, LUA_GLOBALSINDEX, "_DEBUG"); #endif char luaFile[512] = ""; char playlistFile[512] = ""; int beginIndex = 1; if (argc > 1) { int strl = strlen(argv[1]); bool isLuaFile = strcmp(&argv[1][strl-4], ".lua") == 0; if (isLuaFile) { beginIndex = 2; strcpy_s(luaFile, sizeof(luaFile), argv[1]); } else if (strcmp(&argv[1][strl-5], ".sing") == 0 || strcmp(&argv[1][strl-4], ".m3u") == 0 || strcmp(&argv[1][strl-4], ".txt") == 0) { } } if (!luaFile[0]) { lua_pushboolean(L, true); lua_setfield(L, LUA_GLOBALSINDEX, "APPLOADED"); const char* execPath = getExecutablePath(); sprintf_s(luaFile, sizeof(luaFile), "%s\\%s", execPath, "main.lua"); } int temp_int = luaL_loadfile(L,luaFile); int returnval = 0; if (temp_int) { const char *error = lua_tostring(L, -1); printf("Error in file: \"%s\"\n", luaFile); printf("%s\n", error); returnval = 1; } else { const char *error; for (int i = beginIndex; i < argc; i++) lua_pushstring(L, argv[i]); if (docall(L,argc-beginIndex,0)) { error = lua_tostring(L, -1); if (error) std::cout << error; returnval = 1; } } close(L); return returnval; }
void CapASM::Compile(const char * filename) { std::cout << "&Compilation of " << string(filename).c_str() << endl ; char buf[MAX_PATH]; int base_encoding; /* added */ char* p; int i = 1; CleanUP(); // init LUA LUA = lua_open(); lua_atpanic(LUA, (lua_CFunction)LuaFatalError); luaL_openlibs(LUA); luaopen_pack(LUA); tolua_sjasm_open(LUA); // init vars Options::DestionationFName[0] = 0; STRCPY( Options::ListingFName, LINEMAX, "/tmp/caprice.lst"); //TODO generate file name Options::UnrealLabelListFName[0] = 0; STRCPY( Options::SymbolListFName, LINEMAX, "/tmp/caprice.sym"); Options::ExportFName[0] = 0; Options::RAWFName[0] = 0; Options::NoDestinationFile = true; // not *.out files by default // start counter long dwStart; dwStart = GetTickCount(); // get current directory GetCurrentDirectory(MAX_PATH, buf); CurrentDirectory = buf; STRCPY(SourceFNames[SourceFNamesCount++], LINEMAX, filename); if (!SourceFNames[0][0]) { _COUT "No inputfile(s)" _ENDL; return; } if (!Options::DestionationFName[0]) { STRCPY(Options::DestionationFName, LINEMAX, SourceFNames[0]); if (!(p = strchr(Options::DestionationFName, '.'))) { p = Options::DestionationFName; } else { *p = 0; } STRCAT(p, LINEMAX-(p-Options::DestionationFName), ".out"); } // init some vars InitCPU(); // if memory type != none base_encoding = ConvertEncoding; // init first pass InitPass(1); // open lists OpenList(); // open source filenames for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } _COUT "Pass 1 complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; ConvertEncoding = base_encoding; do { pass++; InitPass(pass); if (pass == LASTPASS) { OpenDest(); } for (i = 0; i < SourceFNamesCount; i++) { OpenFile(SourceFNames[i]); } if (PseudoORG) { CurAddress = adrdisp; PseudoORG = 0; } if (pass != LASTPASS) { _COUT "Pass " _CMDL pass _CMDL " complete (" _CMDL ErrorCount _CMDL " errors)" _ENDL; } else { _COUT "Pass 3 complete" _ENDL; } } while (pass < 3);//MAXPASSES); pass = 9999; /* added for detect end of compiling */ if (Options::AddLabelListing) { LabelTable.Dump(); } Close(); if (Options::UnrealLabelListFName[0]) { LabelTable.DumpForUnreal(); } if (Options::SymbolListFName[0]) { LabelTable.DumpSymbols(); } _COUT "Errors: " _CMDL ErrorCount _CMDL ", warnings: " _CMDL WarningCount _CMDL ", compiled: " _CMDL CompiledCurrentLine _CMDL " lines" _END; double dwCount; dwCount = GetTickCount() - dwStart; if (dwCount < 0) { dwCount = 0; } printf(", work time: %.3f seconds", dwCount / 1000); _COUT "" _ENDL; #ifndef UNDER_CE cout << flush; #endif // free RAM delete Devices; Devices = 0; // close Lua lua_close(LUA); //return (ErrorCount != 0); }