Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
illuna-minetest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
illuna-minetest
Commits
19a1ac1f
Commit
19a1ac1f
authored
13 years ago
by
Perttu Ahola
Browse files
Options
Downloads
Patches
Plain Diff
For consistency, implement calling of on_chat_message callbacks in C
parent
30648d1c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data/builtin.lua
+0
-10
0 additions, 10 deletions
data/builtin.lua
src/scriptapi.cpp
+21
-11
21 additions, 11 deletions
src/scriptapi.cpp
with
21 additions
and
21 deletions
data/builtin.lua
+
0
−
10
View file @
19a1ac1f
...
...
@@ -166,14 +166,4 @@ minetest.registered_on_generateds, minetest.register_on_generated = make_registr
minetest
.
registered_on_newplayers
,
minetest
.
register_on_newplayer
=
make_registration
()
minetest
.
registered_on_respawnplayers
,
minetest
.
register_on_respawnplayer
=
make_registration
()
minetest
.
on_chat_message
=
function
(
name
,
message
)
for
i
,
func
in
ipairs
(
minetest
.
registered_on_chat_messages
)
do
local
ate
=
func
(
name
,
message
)
if
ate
then
return
true
end
end
return
false
end
-- END
This diff is collapsed.
Click to expand it.
src/scriptapi.cpp
+
21
−
11
View file @
19a1ac1f
...
...
@@ -1548,18 +1548,28 @@ bool scriptapi_on_chat_message(lua_State *L, const std::string &name,
assert
(
lua_checkstack
(
L
,
20
));
StackUnroller
stack_unroller
(
L
);
// Get minetest.on_chat_message
builtin function
// Get minetest.
registered_
on_chat_message
s
lua_getglobal
(
L
,
"minetest"
);
lua_getfield
(
L
,
-
1
,
"on_chat_message"
);
luaL_checktype
(
L
,
-
1
,
LUA_TFUNCTION
);
// Call function
lua_pushstring
(
L
,
name
.
c_str
());
lua_pushstring
(
L
,
message
.
c_str
());
if
(
lua_pcall
(
L
,
2
,
1
,
0
))
script_error
(
L
,
"error: %s
\n
"
,
lua_tostring
(
L
,
-
1
));
bool
ate
=
lua_toboolean
(
L
,
-
1
);
return
ate
;
lua_getfield
(
L
,
-
1
,
"registered_on_chat_messages"
);
luaL_checktype
(
L
,
-
1
,
LUA_TTABLE
);
int
table
=
lua_gettop
(
L
);
// Foreach
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
table
)
!=
0
){
// key at index -2 and value at index -1
luaL_checktype
(
L
,
-
1
,
LUA_TFUNCTION
);
// Call function
lua_pushstring
(
L
,
name
.
c_str
());
lua_pushstring
(
L
,
message
.
c_str
());
if
(
lua_pcall
(
L
,
2
,
1
,
0
))
script_error
(
L
,
"error: %s
\n
"
,
lua_tostring
(
L
,
-
1
));
bool
ate
=
lua_toboolean
(
L
,
-
1
);
lua_pop
(
L
,
1
);
if
(
ate
)
return
true
;
// value removed, keep key for next iteration
}
return
false
;
}
/*
...
...
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