Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
deaf5cfa
Commit
deaf5cfa
authored
5 years ago
by
James R.
Browse files
Options
Downloads
Patches
Plain Diff
LUA_PushLightUserdata takes the fun out of lib_cvFindVar
parent
0218f58f
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!985
Shaders next merge
,
!754
Cvars returned by CV_FindVar did not work with userdataType
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/lua_consolelib.c
+2
-16
2 additions, 16 deletions
src/lua_consolelib.c
src/lua_script.c
+22
-0
22 additions, 0 deletions
src/lua_script.c
src/lua_script.h
+1
-0
1 addition, 0 deletions
src/lua_script.h
with
25 additions
and
16 deletions
src/lua_consolelib.c
+
2
−
16
View file @
deaf5cfa
...
...
@@ -431,23 +431,9 @@ static int lib_cvRegisterVar(lua_State *L)
static
int
lib_cvFindVar
(
lua_State
*
L
)
{
consvar_t
*
cv
;
if
((
cv
=
CV_FindVar
(
luaL_checkstring
(
L
,
1
))
))
{
lua_settop
(
L
,
1
);
/* We only want one argument in the stack. */
lua_pushlightuserdata
(
L
,
cv
);
/* Now the second value on stack. */
luaL_getmetatable
(
L
,
META_CVAR
);
/*
The metatable is the last value on the stack, so this
applies it to the second value, which is the cvar.
*/
lua_setmetatable
(
L
,
2
);
lua_pushvalue
(
L
,
2
);
LUA_PushLightUserdata
(
L
,
CV_FindVar
(
luaL_checkstring
(
L
,
1
)),
META_CVAR
);
return
1
;
}
else
return
0
;
}
// CONS_Printf for a single player
// Use 'print' in baselib for a global message.
...
...
This diff is collapsed.
Click to expand it.
src/lua_script.c
+
22
−
0
View file @
deaf5cfa
...
...
@@ -568,6 +568,28 @@ fixed_t LUA_EvalMath(const char *word)
return
res
;
}
/*
LUA_PushUserdata but no userdata is created.
You can't invalidate it therefore.
*/
void
LUA_PushLightUserdata
(
lua_State
*
L
,
void
*
data
,
const
char
*
meta
)
{
if
(
data
)
{
lua_pushlightuserdata
(
L
,
data
);
luaL_getmetatable
(
L
,
meta
);
/*
The metatable is the last value on the stack, so this
applies it to the second value, which is the userdata.
*/
lua_setmetatable
(
L
,
-
2
);
lua_pushvalue
(
L
,
-
1
);
}
else
lua_pushnil
(
L
);
}
// Takes a pointer, any pointer, and a metatable name
// Creates a userdata for that pointer with the given metatable
// Pushes it to the stack and stores it in the registry.
...
...
This diff is collapsed.
Click to expand it.
src/lua_script.h
+
1
−
0
View file @
deaf5cfa
...
...
@@ -46,6 +46,7 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump);
void
LUA_DumpFile
(
const
char
*
filename
);
#endif
fixed_t
LUA_EvalMath
(
const
char
*
word
);
void
LUA_PushLightUserdata
(
lua_State
*
L
,
void
*
data
,
const
char
*
meta
);
void
LUA_PushUserdata
(
lua_State
*
L
,
void
*
data
,
const
char
*
meta
);
void
LUA_InvalidateUserdata
(
void
*
data
);
void
LUA_InvalidateLevel
(
void
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment