forked from uspgamedev/luasteam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apps.cpp
78 lines (66 loc) · 2.08 KB
/
apps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "apps.hpp"
// ============================
// ======== SteamApps =========
// ============================
class CallbackListener;
CallbackListener *apps_listener = nullptr;
int apps_ref = LUA_NOREF;
class CallbackListener {
private:
STEAM_CALLBACK(CallbackListener, OnNewUrlLaunchParameters, NewUrlLaunchParameters_t);
};
void CallbackListener::OnNewUrlLaunchParameters(NewUrlLaunchParameters_t *data) {
if (data == nullptr) {
return;
}
lua_State *L = luasteam::global_lua_state;
if (!lua_checkstack(L, 4)) {
return;
}
lua_rawgeti(L, LUA_REGISTRYINDEX, apps_ref);
lua_getfield(L, -1, "onNewUrlLaunchParameters");
if (lua_isnil(L, -1)) {
lua_pop(L, 2);
} else {
lua_call(L, 0, 0);
lua_pop(L, 1);
}
}
// const char * GetCurrentGameLanguage();
EXTERN int luasteam_getCurrentGameLanguage(lua_State *L) {
lua_pushstring(L, SteamApps()->GetCurrentGameLanguage());
return 1;
}
// bool BIsDlcInstalled( AppId_t appID );
EXTERN int luasteam_isDlcInstalled(lua_State *L) {
int appID = luaL_checkint(L, 1);
lua_pushboolean(L, SteamApps()->BIsDlcInstalled(appID));
return 1;
}
// int GetLaunchCommandLine( char *pszCommandLine, int cubCommandLine );
EXTERN int luasteam_getLaunchCommandLine(lua_State *L) {
char pCommandLine[1024];
SteamApps()->GetLaunchCommandLine(pCommandLine, 1024);
lua_pushstring(L, pCommandLine);
return 1;
}
namespace luasteam {
void add_apps(lua_State *L) {
lua_createtable(L, 0, 3);
add_func(L, "getCurrentGameLanguage", luasteam_getCurrentGameLanguage);
add_func(L, "isDlcInstalled", luasteam_isDlcInstalled);
add_func(L, "getLaunchCommandLine", luasteam_getLaunchCommandLine);
lua_pushvalue(L, -1);
apps_ref = luaL_ref(L, LUA_REGISTRYINDEX);
lua_setfield(L, -2, "apps");
}
void init_apps(lua_State *L) {
apps_listener = new CallbackListener();
}
void shutdown_apps(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, apps_ref);
apps_ref = LUA_NOREF;
delete apps_listener;
apps_listener = nullptr;
}
} // namespace luasteam