Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Lua support #6689

Merged
merged 1 commit into from
Oct 8, 2023
Merged

Add Lua support #6689

merged 1 commit into from
Oct 8, 2023

Conversation

AJenbo
Copy link
Member

@AJenbo AJenbo commented Oct 7, 2023

A very basic Lua integration that just links it in the most lame way possible (to see what platforms build) and adds a single event and a way to print message to the player.

The game will look for lua/user.lua on boot up. If you provide the following:

local function OnGameStart()
    devilutionx.message("Hello from " .. _VERSION)
end

Events.OnGameStart.Add(OnGameStart)

You get this once the game loads:
image

The event system is somewhat based on the one from Project Zomboid https://pzwiki.net/wiki/Lua_Events/OnGameStart
Thought a good portion of it is implemented via Lua so mods can register and trigger there own events.

@AJenbo AJenbo force-pushed the lua branch 11 times, most recently from f191e6c to e91c703 Compare October 7, 2023 08:40
Copy link
Contributor

@heinermann heinermann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this uses a limited API for security reasons (i.e. later down the road a mod manager etc), you'll probably want an "unsafe mode" switch to unlock the filesystem and other things (for i.e. integrations such as Twitch and Archipelago).

Source/utils/lua.cpp Outdated Show resolved Hide resolved
Source/utils/lua.cpp Outdated Show resolved Hide resolved
@AJenbo AJenbo force-pushed the lua branch 2 times, most recently from fad7201 to 57a032c Compare October 7, 2023 10:22
@AJenbo
Copy link
Member Author

AJenbo commented Oct 7, 2023

If this uses a limited API for security reasons (i.e. later down the road a mod manager etc), you'll probably want an "unsafe mode" switch to unlock the filesystem and other things (for i.e. integrations such as Twitch and Archipelago).

limited API? unsafe mode? Archipelago?

@heinermann
Copy link
Contributor

If this uses a limited API for security reasons (i.e. later down the road a mod manager etc), you'll probably want an "unsafe mode" switch to unlock the filesystem and other things (for i.e. integrations such as Twitch and Archipelago).

limited API? unsafe mode? Archipelago?

Games like Factorio and Noita limit/restrict the API for security reasons, as people can enable many mods through a simple one-click solution via some mod manager or Steam. I don't know if that's something you wanted to do or not. Some games like Starbound and Noita have a switch that you can enable to allow "unsafe" mods (usually called "unsafe mode", "allow unsafe mods", or "unrestrict lua API" etc). Archipelago.

@AJenbo
Copy link
Member Author

AJenbo commented Oct 7, 2023

Yes, a way to enable multiple mods would be an eventual goal.
I'm not sure if you would consider what we have restricted mode, or what you would be missing from an unsafe mode, so for now we are just starting with the default and can evolve from there as needed.

@heinermann
Copy link
Contributor

It's unrestricted by default I think. A restricted mode would restrict or modify some of the main functions such as require to disallow DLLs or going up one level in a path. io, os, and package would be inaccessible parts of the lua lib. But yeah that stuff can just come later.

@AJenbo AJenbo marked this pull request as ready for review October 7, 2023 19:15
@AJenbo AJenbo force-pushed the lua branch 2 times, most recently from 25a9473 to 2f76f46 Compare October 8, 2023 06:13
Source/utils/lua.cpp Outdated Show resolved Hide resolved
StephenCWills
StephenCWills previously approved these changes Oct 8, 2023
Copy link
Member

@StephenCWills StephenCWills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome.

@AJenbo AJenbo merged commit 706010e into master Oct 8, 2023
19 checks passed
@AJenbo AJenbo deleted the lua branch October 8, 2023 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants