WIP
A side project I work on to learn more about Lua, and It's API for my gmod-lua-shared project
This project aims to provide all necessary functions to run Lua on different threads.
The Goal is to be able to create a ILuaInterface with all of Gmod's libraries, functions and classes.
You can download the latest version(which exist for only 1 day) from the last run workflow, which you can find here
Or you can download the last working version(which exist for 1 month) which was tested from here
NOTE:
This only works on Linux because on Windows creating a ILuaInterface on another thread currently crashes the game.
- Shared Table
- Better Error handling(It loved to crash on any Lua error.)
- bit
- coroutine
- os
- package
- jit
- timer
- hammer (useful for Windows later)
- debug (Missing functions!)
- physenv (Mostly implemented)
-
- physenv.AddSurfaceData
-
- physenv.GetLastSimulationTime
- gameevent (untested!)
- resource (untested!)
- system (untested!)
- engine (Mostly implemented)
-
- engine.GetAddons
-
- [-] engine.GetUserContent (Request it if anyone needs it)
-
- engine.GetUserContent (Disabled because of a random error)
-
- engine.GetGames (Disabled because of a random error)
-
- engine.GetGamemodes (Disabled because of a random error)
-
- engine.ActiveGamemode (Disabled because of a random error)
- gmod (untested!)
- file (Mostly implemented & untested!)
-
- file.AsyncRead
-
- file.Open (Required for file.Read, file.Write and file.Append)
- Angle (untested)
- Vector (untested)
- resource.AddFile & resource.AddSingleFile don't seem to work.
- Idk how gmod implemented (physenv.GetLastSimulationTime)
- Look into ILuaInterface:PushVector being broken.
- Created ILuaInterface should load all Gmod scripts/allow one to do so
- Change ILuaAction to use Enums instead of strings.
- Documentation
- Add all Gmod Enums
- Recreate all Gmod libraries
-
- Implement sql.Query. (Fixes sql and cookie library)
- Add a new way to send data across threads. Maybe something like net messages but for threads?
- Look again into Error handling. Maybe show which file had an error?
- File:Seek seems to have some issues?
I listed all Libraries below that are serverside. Regardless if they are implemented in lua or in c++.
-
- Global(functions)
-
- ai
-
- ai_schedule
-
- ai_task
-
- baseclass
-
- cleanup
-
- concommand
-
- constraint
-
- construct
-
- cookie
-
- cvars
-
- debugoverlay
-
- drive?
-
- duplicator
-
- effects
-
- engine
-
- ents
-
- file
-
- game
-
- gamemode
-
- gmsave
-
- hook
-
- http
-
- list
-
- math
-
- motionsensor
-
- navmesh
-
- net
-
- numpad
-
- player
-
- player_manager
-
- properties
-
- saverestore
-
- scripted_ents
-
- sound
-
- sql
-
- string
-
- table
-
- team
-
- umsg
-
- undo
-
- usermessage
-
- utf8
-
- util
-
- weapons
-
- widgets
- Recreate all Gmod metatable functions
- Cleanup the code
- Make this compatible for x86-64
- Look again into Windows
Example usage:
require("lua_threaded")
iFace = LuaThreaded.CreateInterface() -- Creates an Interface.
iFace:InitGmod() -- Adds all Libraries and Classes
iFace:Autorun() -- Runs all Autorun scripts.
Returns a table containing all Interfaces created.
[ID] = ILuaInterface (Class)
Returns the Interface with the given ID.
Args:
- ID of the given Interface
Creates a new Interface.
Args:
- If the Created Interface should run on the main thread or not.
Rets:
- The newly created Interface.
Closes the given Interface.
Args:
- The Interface to close.
Prints a Message.
This function may be removed in the future!
Args:
- The string to print.
Returns the Shared table.
NOTE: You need to call this function to get an updated version!
Sets a Value inside the shared table.
Returns only the specified value from the shared table.
Args:
- The Key inside the Table
- The Value to set. Allowed Types: Number, Bool, String, Vector, Angle and Table
Runs the given code
Args:
- Code to run.
Initializes all Classes.
This function may be removed in the future!
Initializes all Libraries.
This function may be removed in the future!
Initializes all Enums.
This function may be removed in the future!
Initializes everything for Gmod.
Internally calls InitClasses, InitLibraries and InitEnums.
Loads a function into the Interface.
NOTE: This is unsafe and can cause random crashes.
This function will be removed in the future!
Args:
- Signature of the Function to load.
Loads everything like autorun does.
NOTE: It currently loves to crash. Just call RunFile with init.lua
Update: It seems like it became stable. Could be because I stopped breaking the stack.
Loads:
includes/init.lua
autorun/server/*.lua
autorun/server/sensorbones/*.lua
Runs the given File.
This function could be renamed in the future!
Args:
- Path to the file.
NOTE: This will use theGAME
search path!
Creates the CLuaGameCallback class and implements all functions.
Files:
CLuaGameCallback.h
CLuaGameCallback.cpp
Contains all signatures and functions we need from Gmod.
Files:
detours.h
detours.cpp
Contains all ILuaInterface metatable functions.
Files:
lua_ILuaInterface.h
lua_ILuaInterface.cpp
Contains our LuaThread table and all its functions.
Files:
lua_LuaThread.h
lua_LuaThread.cpp
Contains our LuaThread table and all its functions.
Files:
lua_Enums.h
lua_Enums.cpp
Contains all implemented Global functions.
Status: Unfinished
Files:
library_Global.h
library_Global.cpp
Contains all implemented net functions.
Status: Unfinished
Files:
library_net.h
library_net.cpp
Contains all implemented Vector functions.
Status: Unfinished + Broken
Files:
class_vector.h
class_vector.cpp
Contains important functions PushValue, FillValue and so on.
Files:
ILuaConVars.h
(Needed for library_Global)lua_utils.h
lua_utils.cpp
Contains module base and manages everything for Init and Shutdown.
Files:
lua_threaded.h
lua_threaded.cpp