Hi !
I'm trying to start playing with LUA in Spring, in order to create custom commands callable in game, but I'm having troubles in finding a starting point. I didn't find any tutorial for such a thing, but I may not have looked at the proper place... Does anyone know where I can find documentation about that ? Alternatively, what I would like to be able to do, to start with, is just a "Hello World", somehting that would print "Hello World" on the Spring screen if I write e.g.:
/luaui hello
Any help would be greatly appreciated.
Thanks a lot,
Hello World in Lua ?
Moderator: Moderators
Hello, you can start by going through the following tutorial:
http://lua-users.org/wiki/TutorialDirectory
After that, you can check out the .lua widget files and look up in \Spring\LuaUI\API.txt the functions they use. When you start writing your own widgets, don't hesitate to borrow as much code as you can from existing widgets!
Writing "hello world" in Spring is slightly more complex than stand-alone Lua.
This function sends the commands to the spring prompt as though you typed in directly:
Your need to insert it in a widget to execute it.
Save this as init_helloWorld.lua in your Widgets folder.
http://lua-users.org/wiki/TutorialDirectory
After that, you can check out the .lua widget files and look up in \Spring\LuaUI\API.txt the functions they use. When you start writing your own widgets, don't hesitate to borrow as much code as you can from existing widgets!
Writing "hello world" in Spring is slightly more complex than stand-alone Lua.
Code: Select all
Spring.SendCommands({"echo hello world"})
Code: Select all
/echo hello world
Code: Select all
function widget:GetInfo() -- Required: the widget won't load without it.
return {
name = "My First Widget",
desc = "Displays 'hello world'",
author = "quantum",
date = "Jan 27, 2007",
license = "GNU GPL, v2 or later",
layer = 0,
enabled = true -- loaded by default?
}
end
function widget:Initialize() -- Runs as the widget starts.
Spring.SendCommands({"echo hello world"})
end
Last edited by quantum on 27 Jan 2007, 13:22, edited 1 time in total.
A couple of good sources for lua information:
http://www.lua.org/pil/
http://www.lua.org/manual/5.0/manual.html
http://www.lua.org/pil/
http://www.lua.org/manual/5.0/manual.html