Ejemplo n.º 1
0
int ustring_SearchPath(lua_State *L)
{
	const wchar_t* lpPath = opt_utf8_string(L, 1, NULL);
	const wchar_t* lpFileName = check_utf8_string(L, 2, NULL);
	const wchar_t* lpExtension = opt_utf8_string(L, 3, NULL);
	wchar_t buf[2048];
	wchar_t* lpFilePart;
	DWORD result = SearchPathW(
	                   lpPath,         // address of search path
	                   lpFileName,	    // address of filename
	                   lpExtension,	  // address of extension
	                   sizeof(buf)/sizeof(wchar_t),	  // size, in characters, of buffer
	                   buf,	          // address of buffer for found filename
	                   &lpFilePart 	  // address of pointer to file component
	               );

	if(result > 0)
	{
		push_utf8_string(L, buf, -1);
		push_utf8_string(L, lpFilePart, -1);
		return 2;
	}

	return 0;
}
Ejemplo n.º 2
0
static int ll_searchpath (lua_State *L) {
  const wchar_t *f = searchpath(L, luaL_checkstring(L, 1),
                                   check_utf8_string(L, 2, NULL),
                                   opt_utf8_string(L, 3, L"."),
                                   opt_utf8_string(L, 4, LUA_DIRSEP));
  if (f != NULL) return 1;
  else {  /* error message is on top of the stack */
    lua_pushnil(L);
    lua_insert(L, -2);
    return 2;  /* return nil + error message */
  }
}
Ejemplo n.º 3
0
static int win_SetEnv(lua_State *L)
{
	const wchar_t* name = check_utf8_string(L, 1, NULL);
	const wchar_t* value = opt_utf8_string(L, 2, NULL);
	BOOL res = SetEnvironmentVariableW(name, value);
	return lua_pushboolean(L, res), 1;
}
Ejemplo n.º 4
0
/*
** this function has a separated environment, which defines the
** correct __close for 'popen' files
*/
static int io_popen(lua_State *L)
{
    const wchar_t *filename = check_utf8_string(L, 1, NULL);
    const wchar_t *mode = opt_utf8_string(L, 2, L"r");
    FILE **pf = newfile(L);
    *pf = lua_popen(L, filename, mode);
    return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
Ejemplo n.º 5
0
static int win_ShellExecute(lua_State *L)
{
	HWND hwnd = lua_isuserdata(L, 1) ? lua_touserdata(L, 1) : NULL;
	const wchar_t* lpOperation = opt_utf8_string(L, 2, NULL);
	const wchar_t* lpFile = check_utf8_string(L, 3, NULL);
	const wchar_t* lpParameters = opt_utf8_string(L, 4, NULL);
	const wchar_t* lpDirectory = opt_utf8_string(L, 5, NULL);
	INT nShowCmd = (INT)luaL_optinteger(L, 6, SW_SHOWNORMAL);
	HINSTANCE hinst = ShellExecuteW(
	                      hwnd,           // handle to parent window
	                      lpOperation,    // pointer to string that specifies operation to perform
	                      lpFile,         // pointer to filename or folder name string
	                      lpParameters,   // pointer to string that specifies executable-file parameters
	                      lpDirectory,    // pointer to string that specifies default directory
	                      nShowCmd        // whether file is shown when opened
	                  );
	lua_pushinteger(L, (INT_PTR)hinst);
	return 1;
}
Ejemplo n.º 6
0
// Result = DeleteRegValue (Root, Key, ValueName [, samDesired])
//   Root:      [string], one of "HKLM", "HKCC", "HKCR", "HKCU", "HKU"
//   Key:       registry key, [string]
//   ValueName: value name, [optional string]
//   samDesired: access mask, [flag] ("KEY_WOW64_32KEY" or "KEY_WOW64_64KEY"; the default is 0)
// Returns:
//   Result:    TRUE if success, FALSE if failure, [boolean]
static int win_DeleteRegValue(lua_State *L)
{
	HKEY hKey;
	HKEY hRoot = CheckHKey(L, 1);
	const wchar_t* Key = check_utf8_string(L, 2, NULL);
	const wchar_t* Name = opt_utf8_string(L, 3, NULL);
	REGSAM samDesired = (REGSAM) OptFlags(L, 4, 0) | KEY_SET_VALUE;
	int res = 0;
	if (RegOpenKeyExW(hRoot, Key, 0, samDesired, &hKey) == ERROR_SUCCESS)
	{
		res = (RegDeleteValueW(hKey, Name) == ERROR_SUCCESS);
		RegCloseKey(hKey);
	}
	lua_pushboolean(L, res);
	return 1;
}
Ejemplo n.º 7
0
int ustring_GetDriveType(lua_State *L)
{
	const wchar_t *root = opt_utf8_string(L, 1, NULL);
	const char* out;
	UINT tp = GetDriveTypeW(root);

	switch(tp)
	{
		default:
		case 0:               out = "unknown type";      break;
		case 1:               out = "no root directory"; break;
		case DRIVE_REMOVABLE: out = "removable";         break;
		case DRIVE_FIXED:     out = "fixed";             break;
		case DRIVE_REMOTE:    out = "remote";            break;
		case DRIVE_CDROM:     out = "cdrom";             break;
		case DRIVE_RAMDISK:   out = "ramdisk";           break;
	}

	lua_pushstring(L, out);
	return 1;
}
Ejemplo n.º 8
0
static int io_open(lua_State *L)
{
    const wchar_t *filename = check_utf8_string(L, 1, NULL);
    const wchar_t *mode = opt_utf8_string(L, 2, L"r");
    FILE **pf = newfile(L);
    int i = 0;

    /* check whether 'mode' matches '[rwa]%+?b?' */
    if(!(mode[i] != L'\0' && wcschr(L"rwa", mode[i++]) != NULL &&
            (mode[i] != L'+' || ++i) &&  /* skip if char is '+' */
            (mode[i] != L'b' || ++i) &&  /* skip if char is 'b' */
            (mode[i] == L'\0')))
    {
        push_utf8_string(L, mode, -1);
        return luaL_error(L, "invalid mode " LUA_QS
                          " (should match " LUA_QL("[rwa]%%+?b?") ")", lua_tostring(L, -1));
    }

    *pf = _wfopen(filename, mode);
    return (*pf == NULL) ? pushresult(L, 0, filename) : 1;
}
Ejemplo n.º 9
0
static int ustring_system(lua_State *L)
{
	const wchar_t *str = opt_utf8_string(L, 1, NULL);
	lua_pushinteger(L, _wsystem(str));
	return 1;
}