Created
November 19, 2015 05:32
-
-
Save pkulchenko/73fb5c32f20d90ece1db to your computer and use it in GitHub Desktop.
Simplified starter for ZeroBrane Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <sys/types.h> | |
#include <windows.h> | |
int main (int argc, char *argv[]) | |
{ | |
char buffer[MAX_PATH],*file; | |
if (!GetFullPathName(argv[0],MAX_PATH,buffer,&file)) { | |
MessageBox(NULL, | |
TEXT("Couldn't find the correct working directory"), | |
TEXT("Failed to start editor"), | |
MB_OK|MB_ICONERROR); | |
return 1; | |
} | |
char *arg = GetCommandLine(); | |
char *lua = "bin\\lua.exe src\\main.lua "; | |
char *cl = (char*)malloc(strlen(lua) + strlen(file) + strlen(arg)); | |
strcpy(cl, lua); | |
strcat(cl, file); | |
// since the name can be quoted in arg, but may not be in argv, | |
// account for those quotes | |
strcat(cl, arg + strlen(argv[0]) | |
+ (arg[0] == '"' && argv[0][0] != '"' ? 2 : 0)); | |
if (file!=NULL) *file = '\0'; // finish the string; don't need the appname | |
STARTUPINFO si; | |
PROCESS_INFORMATION pi; | |
ZeroMemory(&si, sizeof(STARTUPINFO)); | |
si.cb = sizeof(si); | |
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION)); | |
// Start the child process. | |
if(!CreateProcess(NULL, cl, NULL, NULL, FALSE, | |
CREATE_NO_WINDOW, NULL, buffer, &si, &pi)) { | |
MessageBox(NULL, | |
TEXT("Couldn't launch Lua interpreter"), | |
TEXT("Failed to start editor"), | |
MB_OK|MB_ICONERROR); | |
return 1; | |
} | |
// Wait until child process exits. | |
WaitForSingleObject(pi.hProcess, INFINITE); | |
free(cl); | |
// Close process and thread handles. | |
CloseHandle(pi.hProcess); | |
CloseHandle(pi.hThread); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment