Coder Social home page Coder Social logo

gmod-lua-threaded's Introduction

gmod-lua-threaded

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.

What is implemented

  • Shared Table
  • Better Error handling(It loved to crash on any Lua error.)

Libraries

  • bit
  • coroutine
  • os
  • package
  • jit
  • timer
  • hammer (useful for Windows later)

Unfinished/Untested

  • 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)

Classes

  • Angle (untested)
  • Vector (untested)

Current Issues

  • resource.AddFile & resource.AddSingleFile don't seem to work.
  • Idk how gmod implemented (physenv.GetLastSimulationTime)
  • Look into ILuaInterface:PushVector being broken.

ToDo/Testing

  • 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?

Bugs

  • 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

API

Example usage:

require("lua_threaded")
iFace = LuaThreaded.CreateInterface() -- Creates an Interface.
iFace:InitGmod() -- Adds all Libraries and Classes
iFace:Autorun() -- Runs all Autorun scripts.

LuaThreaded

LuaThreaded.GetAllInterfaces()

Returns a table containing all Interfaces created.
[ID] = ILuaInterface (Class)

LuaThreaded.GetInterface(number ID)

Returns the Interface with the given ID.

Args:

  1. ID of the given Interface

LuaThreaded.CreateInterface(boolean not_threaded = false)

Creates a new Interface.

Args:

  1. If the Created Interface should run on the main thread or not.

Rets:

  1. The newly created Interface.

LuaThreaded.CloseInterface(ILuaInterface interface)

Closes the given Interface.

Args:

  1. The Interface to close.

LuaThreaded.Msg(string msg)

Prints a Message.
This function may be removed in the future!

Args:

  1. The string to print.

LuaThreaded.GetTable()

Returns the Shared table.
NOTE: You need to call this function to get an updated version!

LuaThreaded.SetValue(string key, any value)

Sets a Value inside the shared table.

LuaThreaded.GetValue(string key)

Returns only the specified value from the shared table.

Args:

  1. The Key inside the Table
  2. The Value to set. Allowed Types: Number, Bool, String, Vector, Angle and Table

ILuaInterface

ILuaInterface:RunString(string code)

Runs the given code

Args:

  1. Code to run.

ILuaInterface:InitClasses()

Initializes all Classes.
This function may be removed in the future!

ILuaInterface:InitLibraries()

Initializes all Libraries.
This function may be removed in the future!

ILuaInterface:InitEnums()

Initializes all Enums.
This function may be removed in the future!

ILuaInterface:InitGmod()

Initializes everything for Gmod.
Internally calls InitClasses, InitLibraries and InitEnums.

ILuaInterface:LoadFunction(string sig)

Loads a function into the Interface.
NOTE: This is unsafe and can cause random crashes.
This function will be removed in the future!

Args:

  1. Signature of the Function to load.

ILuaInterface:Autorun()

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

ILuaInterface:RunFile(string path)

Runs the given File.
This function could be renamed in the future!

Args:

  1. Path to the file.
    NOTE: This will use the GAME search path!

Structure

CLuaGameCallback class

Creates the CLuaGameCallback class and implements all functions.

Files:

  • CLuaGameCallback.h
  • CLuaGameCallback.cpp

detours

Contains all signatures and functions we need from Gmod.

Files:

  • detours.h
  • detours.cpp

lua_ILuaInterface

Contains all ILuaInterface metatable functions.

Files:

  • lua_ILuaInterface.h
  • lua_ILuaInterface.cpp

lua_LuaThread

Contains our LuaThread table and all its functions.

Files:

  • lua_LuaThread.h
  • lua_LuaThread.cpp

lua_Enums

Contains our LuaThread table and all its functions.

Files:

  • lua_Enums.h
  • lua_Enums.cpp

library_Global

Contains all implemented Global functions.
Status: Unfinished

Files:

  • library_Global.h
  • library_Global.cpp

library_net

Contains all implemented net functions.
Status: Unfinished

Files:

  • library_net.h
  • library_net.cpp

class_vector

Contains all implemented Vector functions.
Status: Unfinished + Broken

Files:

  • class_vector.h
  • class_vector.cpp

lua_utils

Contains important functions PushValue, FillValue and so on.

Files:

  • ILuaConVars.h (Needed for library_Global)
  • lua_utils.h
  • lua_utils.cpp

lua_threaded

Contains module base and manages everything for Init and Shutdown.

Files:

  • lua_threaded.h
  • lua_threaded.cpp

gmod-lua-threaded's People

Contributors

raphaelit7 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.