Author Topic: Scripting API (Coding scrapbook)  (Read 1602 times)

0 Members and 1 Guest are viewing this topic.

Offline WMCoolmon

  • Purveyor of space crack
  • 213
Scripting API (Coding scrapbook)
Coding stuff.

I recently revamped the way that Lua scripting is handled to make it easier to deal with, and get rid of the crappy arrays. I based some of it on the way the console is done.

Functions
So, to define a function, you don't need much.
Code: [Select]
LUA_FUNC(getNumEscortShips, l_Mission, "Gets escort ship", NULL, "Ship object") {
return lua_return_args(L, "i", hud_escort_num_ships_on_list());
}

Using the LUA_FUNC macro, the first parameter determines the name in Lua; the second parameter is the object or library you want to associate the function with; the third parameter is the description, fourth is arguments list, and fifth is the return values.

As you can see, I've renamed script_return_args to lua_return_args, the same can be said for script_parse_args.

Objects
Code: [Select]
lua_obj<int> l_Shipclass("shipclass", "Ship class object");Defines the "shipclass" object, this is the data from an entry in ships.tbl. The <> defines the C type that this object should be associated with (I'm using the index into Ship_info here, thus an int). The name of the new object variable is passed to LUA_FUNC (see above). The next variable is the name of the object in Lua. This doesn't really do anything except in the description area, so I'm considering getting rid of it. Finally, the last parameter is the description.

Libraries
Code: [Select]
lua_lib l_Graphics("gr", "Graphics Library");Defines the Graphics library. "gr" is what's used to get at it from scripting, rather than "grpc"; four letters is crappy, especially since I cant pad "Hud" out to four. :wtf: "Graphics library" is the description

metapage
I've updated the format of the metapage so it looks a bit more spiffy (-output_scripting)

New hooks

Coming soon...
-C