Skip to content

Commit

Permalink
Added get_platform() and platform_supported()
Browse files Browse the repository at this point in the history
  • Loading branch information
stetre committed May 2, 2024
1 parent 0f16669 commit 5b90fdc
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 0 deletions.
9 changes: 9 additions & 0 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,15 @@ <h3 id="_initialization_version_and_errors">Initialization, version and errors</
</li>
</ul>
</div>
<div id="get_platform" class="ulist">
<ul>
<li>
<p><em>platform</em> = <strong>get_platform</strong>( )<br>
<em>boolean</em> = <strong>platform_supported</strong>(<em>platform</em>)<br>
<span class="small">'<em>platform</em>': '<em>null</em>' | '<em>win32</em>' | '<em>cocoa</em>' | '<em>wayland</em>' | '<em>x11</em>'.</span></p>
</li>
</ul>
</div>
<div id="set_error_callback" class="ulist">
<ul>
<li>
Expand Down
5 changes: 5 additions & 0 deletions doc/initialization.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ MoonGLFW automatically calls *glfwInit*( ) when it is loaded, and *glfwTerminate
[[get_version_string]]
* _string_= *get_version_string*( )

[[get_platform]]
* _platform_ = *get_platform*( ) +
_boolean_ = *platform_supported*(_platform_) +
[small]#'_platform_': '_null_' | '_win32_' | '_cocoa_' | '_wayland_' | '_x11_'.#

[[set_error_callback]]
* *set_error_callback*([_func_]) +
[small]#The _func_ callback is executed as *_func(ec, descr)_* where _ec_ (an integer) is the
Expand Down
11 changes: 11 additions & 0 deletions examples/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ print(glfw._VERSION)
print(glfw._GLFW_VERSION)
print(glfw.get_version())
print(glfw.get_version_string())

--[[
print('platform: ' .. glfw.get_platform())
local platforms = glfw.enum('platform')
print(table.concat(platforms, ', '))
for _, p in ipairs(platforms) do
if p ~= 'any' then
print(p, glfw.platform_supported(p))
end
end
--]]
3 changes: 3 additions & 0 deletions src/getproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ static int Init(lua_State *L)
OPT(GetGamepadState);
// GLFW ver 3.4.0:
OPT(GetWindowTitle);
OPT(GetPlatform);
OPT(PlatformSupported);

//#ifdef VULKAN requires GLFW version >= 3.20
OPT(GetProcAddress);
OPT(VulkanSupported);
Expand Down
2 changes: 2 additions & 0 deletions src/getproc.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ typedef struct {
PFN_glfwGetGamepadName GetGamepadName;
PFN_glfwGetGamepadState GetGamepadState;
PFN_glfwGetWindowTitle GetWindowTitle;
PFN_glfwGetPlatform GetPlatform;
PFN_glfwPlatformSupported PlatformSupported;

//#ifdef VULKAN
PFN_glfwGetProcAddress GetProcAddress;
Expand Down
21 changes: 21 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,25 @@ static int InitHint(lua_State *L)
}
#undef ENUM

static int GetPlatform(lua_State *L)
{
int platform;
CheckPfn(L, GetPlatform, 3, 4, 0);
platform = glfw.GetPlatform();
pushplatform(L, platform);
return 1;
}


static int PlatformSupported(lua_State *L)
{
int platform;
CheckPfn(L, PlatformSupported, 3, 4, 0);
platform = checkplatform(L, 1);
lua_pushboolean(L, glfw.PlatformSupported(platform));
return 1;
}

/*------------------------------------------------------------------------------*
| Registration |
*------------------------------------------------------------------------------*/
Expand All @@ -189,6 +208,8 @@ static const struct luaL_Reg Functions[] =
{
{ "init", Init },
{ "init_hint", InitHint },
{ "get_platform", GetPlatform },
{ "platform_supported", PlatformSupported },
{ "get_version", GetVersion },
{ "get_version_string", GetVersionString },
{ "now", Now },
Expand Down
5 changes: 5 additions & 0 deletions src/pfn.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ typedef int (*PFN_glfwJoystickIsGamepad)(int jid);
typedef int (*PFN_glfwUpdateGamepadMappings)(const char* string);
typedef const char* (*PFN_glfwGetGamepadName)(int jid);
typedef int (*PFN_glfwGetGamepadState)(int jid, GLFWgamepadstate* state);
// GLFW 3.4
typedef const char* (*PFN_glfwGetWindowTitle)(GLFWwindow* window);
typedef int (*PFN_glfwGetPlatform)(void);
typedef int (*PFN_glfwPlatformSupported)(int platform);

/* Typedefs for glfw2native.h functions (to avoid including native headers)
*/
Expand Down Expand Up @@ -182,5 +185,7 @@ typedef const char* (*PFN_glfwGetX11SelectionString)(void);
typedef int (*PFN_glfwGetOSMesaColorBuffer)(GLFWwindow* window, int* width, int* height, int* format, void** buffer);
typedef int (*PFN_glfwGetOSMesaDepthBuffer)(GLFWwindow* window, int* width, int* height, int* bytesPerValue, void** buffer);
typedef void* /* OSMesaContext */ (*PFN_glfwGetOSMesaContext)(GLFWwindow* window);
// GLFW 3.4
//typedef id glfwGetCocoaView(GLFWwindow* window);

#endif /* pfnDEFINED */

0 comments on commit 5b90fdc

Please sign in to comment.