When you want to propagate something from the console into the Lua using the interfaces is indeed the way to go. I have just played with the following and works fine for me:
control.lua in foo mod:
Code: Select all
remote.addinterface("foo",
{
testprint = function(msg)
game.player.print(tostring(msg))
return glob.foo
end,
gimme = function(name, count)
game.player.character.insert{name=name, count=count}
end,
gimmecar = function()
game.player.character.insert{name="car", count=1}
end
})
game.onload(function()
glob.foo = "foo"
end)
To get a car:
Code: Select all
remote.call("foo", "gimmecar")
Code: Select all
remote.call("foo", "gimme", "gun-turret", 10)
Code: Select all
remote.call("foo", "testprint", "this is a test message")
Code: Select all
game.player.print(remote.call("foo", "testprint", "this is a test message"))
1) Stay away from using the remote.interfaces for discovering the interfaces. If it is used in the mod that defines an interface itself the game will most probably crash. This is because of internal corruption of different lua states.
2) The commands that are run in the interface function must not produce ANY error. That is not handled well at all right now. The inner lua states get corrupted and soonish the whole game crashes. What I mean here are "innocent" mistakes like:
Code: Select all
game.player.character.print("xxx")
Or using wrong names for items:
Code: Select all
game.player.character.insert{name="ammo-turret", count=1}
I am aware of these two issues as of now. If you find any more please report them. We will fix these and they will be part of the next release. The question remains whether the next release will be 0.3.3 (soonish with these bugfixes) or 0.4.0 (end of April with the new features).