Page 1 of 1

[0.4.7] ScriptAPI separation

Posted: Fri May 24, 2013 23:16
by PilzAdam
Hello everyone!
The scriptapi in the source code of the engine was moved into a subfolder. This is a huge change in the engine structure and was mostly done by sapier with some tweaks by celeron55 and kahrl. The end-users will most likely not notice anything from this change.

Modders should note, that env functions are now in the global minetest table, that means one calls a function now like this

Code: Select all

minetest.<function>
instead of

Code: Select all

minetest.env:<function>
The old way will be supported for a long while, though, so mods don't break.

Everyone who has a pull request that touches the scriptapi in the engine should rebase it to the new system.

Also the functions minetest.env:add_firefly() and minetest.env:add_rat() are removed, since they are marked as deprecated for a long time and had no functionality.

Posted: Sat May 25, 2013 13:14
by rarkenin
It would be good if announcements also had a link to a github revision whenever practical

Posted: Sat May 25, 2013 13:21
by kaeza

Posted: Sat May 25, 2013 23:49
by Evergreen
Huhboy, this is going to make a ton of mods not work. It is a good idea though.

Posted: Sat May 25, 2013 23:53
by PilzAdam
Evergreen wrote:Huhboy, this is going to make a ton of mods not work. It is a good idea though.
No mods break. The old way will be supported for a long time.

Posted: Sun May 26, 2013 00:09
by Evergreen
PilzAdam wrote:
Evergreen wrote:Huhboy, this is going to make a ton of mods not work. It is a good idea though.
No mods break. The old way will be supported for a long time.
Ah okay.

Posted: Sun May 26, 2013 03:07
by paramat
There seems to be a trick for more speed:

Code: Select all

local env = minetest.env
...
env:add_node({x=x,y=y,z=z},{name="default:stone"})
How would i retain the benefit of this trick?

Posted: Sun May 26, 2013 03:40
by kaeza
This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})

Posted: Sun May 26, 2013 04:45
by paramat
Ah cool ... thank you!

Posted: Tue May 28, 2013 19:02
by Jonathan
kaeza wrote:This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})
I'm curious, why does this make adding a node faster? Also, I am assuming that this trick would work for the function set_node as well (what exactly is the difference between add_node and set_node anyway, or is there a difference?).

Posted: Tue May 28, 2013 19:29
by PilzAdam
Jonathan wrote:
kaeza wrote:This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})
I'm curious, why does this make adding a node faster? Also, I am assuming that this trick would work for the function set_node as well (what exactly is the difference between add_node and set_node anyway, or is there a difference?).
lua-api.txt wrote:minetest.add_node(pos, node): alias set_node(pos, node)

Posted: Tue May 28, 2013 19:40
by Jonathan
PilzAdam wrote:
Jonathan wrote:
kaeza wrote:This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})
I'm curious, why does this make adding a node faster? Also, I am assuming that this trick would work for the function set_node as well (what exactly is the difference between add_node and set_node anyway, or is there a difference?).
lua-api.txt wrote:minetest.add_node(pos, node): alias set_node(pos, node)
Did they used to be different? I was curious as to why there was two functions.

Posted: Tue May 28, 2013 20:38
by qznc
Jonathan wrote:
kaeza wrote:This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})
I'm curious, why does this make adding a node faster?
In scripting languages practically everything is a hash map (Javascript,Python,Lua,Ruby,etc). This means "minetest.add_node" performs a lookup into a hash map to get the method called "add_node" from the minetest object. By storing the method in a local variable, you do this lookup only once.

Nevertheless, unless you call the method hundreds or thousands of times, I bet there will be no measurable performance difference.

Posted: Tue May 28, 2013 20:44
by Jonathan
qznc wrote:
Jonathan wrote:
kaeza wrote:This should do the trick:

Code: Select all

local add_node = minetest.add_node
add_node({x=x,y=y,z=z},{name="default:stone"})
I'm curious, why does this make adding a node faster?
In scripting languages practically everything is a hash map (Javascript,Python,Lua,Ruby,etc). This means "minetest.add_node" performs a lookup into a hash map to get the method called "add_node" from the minetest object. By storing the method in a local variable, you do this lookup only once.

Nevertheless, unless you call the method hundreds or thousands of times, I bet there will be no measurable performance difference.
Thanks for the info. :)