Author Topic: Lua Utilities library  (Read 1645 times)

0 Members and 1 Guest are viewing this topic.

Offline m!m

  • 211
I put together a small lua package that contains a few things that could be useful for a lua coder:

require package loader
The package contains a loader implementation so you can use require with modules that exist within the file system of FSO (that also includes VP files).
There is not much more to know about it except that when the loader has been initialized the variable cfileRequireInitialized is set to true. You can use that to delay the usage of require until the loaders have been initialized.

Coroutine manager
You can now use coroutines within FSO to execute code distributed over multiple frames (if you don't know what coroutines are you can read this tutorial).
To use coroutines you first have to require the 'fsoCoroutine' module (fsoCoroutine = require("fsoCoroutine")).
The currently available function in that module are:
  • startCoroutine(function): Calling this with a function argument will create a new coroutine and return it. From that point on the coroutine will be resumed every frame until it is done.
  • waitUntil(function): This function will yield the coroutine until the given function returns true. The argument can be any function but this package contains some functions that handle most use-cases.
  • secondsPassed(timeDiff): Returns a function that returns false until the given amount of seconds have passed based on the mission time of FSO. This function should be used with waitUntil() (see the example for a usage example).

Code: [Select]
local fc = require("fsoCoroutine")




« Last Edit: November 25, 2014, 05:18:45 am by m!m »


Offline niffiwan

  • 211
  • Eluder Class
Sounds pretty cool!  :yes:
Creating a fs2_open.log | Red Alert Bug = Hex Edit | MediaVPs 2014: Bigger HUD gauges | 32bit libs for 64bit Ubuntu
Debian Packages (testing/unstable): Freespace2 | wxLauncher
m|m: I think I'm suffering from Stockholm syndrome. Bmpman is starting to make sense and it's actually written reasonably well...


Offline Nuke

  • Ka-Boom!
  • 212
  • Mutants Worship Me
this is very useful. now you can write stand alone scripts and let everyone require them in their own code.

i guess it would be good practice to put binary module files for all platforms into your file structure/vp files. it should in theory work the same on linux as windows after that.
« Last Edit: November 24, 2014, 05:34:22 pm by Nuke »
I can no longer sit back and allow communist infiltration, communist indoctrination, communist subversion, and the international communist conspiracy to sap and impurify all of our precious bodily fluids.

Nuke's Scripting SVN


Offline m!m

  • 211
I created a Github repository with the code for easier version management.
I changed the loaded to also try loading .lc files if the modder distributed a precompiled version of the module.