Skip to content
/ slimer Public

Sleep, msleep, and usleep for Lua as a C/C++ extension. Also provides a high resolution (<1us) clock that can be used as a timer.

License

Notifications You must be signed in to change notification settings

dexhug/slimer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to the Slimer Module!

Slimer (sleep and timer) provides the sleep, msleep, and usleep functions to Lua as a C/C++ extension. It also provides a high resolution (<1us) clock that can be used for timing purposes. It is currently supported on Windows only.

Usage

-- USAGE OF SLIMER IN LUA

-- if your compiled DLL is not already in the Lua path you must add it
package.cpath = "path\\to\\your\\dll\\?.dll" .. package.cpath

-- use the appropriate 64 or 32 bit version for your system
local slimer = require("slimerx64") -- 64 bit
local slimer = require("slimerx86") -- 32 bit

local sleep  = slimer.sleep  -- sleep by seconds
local msleep = slimer.msleep -- sleep by milliseconds
local usleep = slimer.usleep -- sleep by microseconds
-- see docs if you don't understand below
local frequency   = slimer.frequency() -- returns integer indicating frequency of your PerformanceCounter
local currentTime = slimer.clock()     -- returns current time since system startup with unit and precision of period
local period      = slimer.period()    -- returns float indicating period of your PerformanceCounter in seconds

sleep(10)    -- sleep for 10 seconds
msleep(2400) -- sleep for 2.4 seconds
usleep(100)  -- sleep for .1 milliseconds

local startTime = slimer.clock() -- get current time
--[[
    EXECUTE SOME CODE
  ]]
local endTime = slimer.clock() -- get end time

print("Total time elapsed during code block:", (endTime - startTime) * period * 1000, "milliseconds")

Installation instructions

Slimer uses the Lua C API, which means that you cannot simply load the module as you normally would using "require". You have to first compile the module into an executable that Lua can use. Creating a DLL through Microsoft Visual Studio is the easiest, so I have provided instructions for this method. If you are aware of the other compilation methods you are probably already knowledgeable enough to use them. Please note that you need your own compiled version of Lua either as a standalone or an embedded system, and you will require the Lua header files, an import library (.lib file), and a Lua DLL.

Creating a DLL with the Visual Studio IDE

  1. Open Visual Studio and select File --> New --> Project.
  2. Look for the Visual C++ tab, and select Windows Desktop Wizard (or DLL if you understand the differences).
  3. Select Dynamic Link Library from the next dialog box and create the project.
  4. Put either the slimerx64 or slimerx86 C++/C file and the respective header file into the project by selecting Open.
  5. In the Solution Explorer, select the project, then on the menu select Project --> Properties.
  6. Make sure your configuration is set to All Configurations and the Platform is set to your Slimer bit version.
  7. Navigate to the C/C++ tab and go to General.
  8. Under Additional Include Directories, add the directory path that contains the Lua header files (lua.h, lauxlib.h, etc).
  9. Go to Advanced in the same tab, and set Compile As to C if you are using the 32 bit version, and C++ for the 64 bit version.
  10. Go to the Linker tab and hit General.
  11. Under Additional Library Directories add the directory path that contains your Lua5X.lib file (the binaries do not come with this file included, you must have compiled Lua yourself or get the .lib file somewhere). The .lib file must be for the 32 or 64 bit version of Lua depending on which one you are using, and of course you must use the Slimer version that corresponds to that.
  12. Under Linker --> Input --> Additional Dependencies add the name of the .lib file.
  13. Click OK on the Properties and build your project by selecting Build --> Build Solution.
  14. If everything works correctly you can now use "require" as you normally would and use Slimer. Enjoy!

If you run into problems with the stdafx header, you can delete all the extra files that the project automatically created, and then click Project --> Properties --> C/C++ --> Precompiled Headers --> Precompiled Header and set it to Not Using Precompiled Headers. Also, make sure the Lua DLL is in a the same directory as your Slimer DLL, or link the path in addition to the above instructions.

About

Sleep, msleep, and usleep for Lua as a C/C++ extension. Also provides a high resolution (<1us) clock that can be used as a timer.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published