Skip to content

Instantly share code, notes, and snippets.

@pkulchenko
Created November 19, 2015 05:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkulchenko/73fb5c32f20d90ece1db to your computer and use it in GitHub Desktop.
Save pkulchenko/73fb5c32f20d90ece1db to your computer and use it in GitHub Desktop.
Simplified starter for ZeroBrane Studio
#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