Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
254 commits
Select commit Hold shift + click to select a range
27ccf7b
fix: meta SetTab
Akeit0 Apr 27, 2025
fbdf8f7
fix: table.unpack with arg value int32 overflow
Akeit0 Apr 27, 2025
fad3b5e
fix: meta unary methods vararg
Akeit0 Apr 27, 2025
4c54e42
fix: meta concat callstack
Akeit0 Apr 27, 2025
0c3dd1c
fix: getmetatable for all types
Akeit0 Apr 27, 2025
c15dcab
fix: meta newindex target
Akeit0 Apr 27, 2025
4783ea0
fix: uncleared stack for call
Akeit0 Apr 27, 2025
c5d3f9f
fix: string.find empty pattern
Akeit0 Apr 27, 2025
d994432
Rename fields and parameters
Akeit0 Apr 27, 2025
a00b966
Reformat
Akeit0 Apr 27, 2025
21eeb52
fix: parser
Akeit0 Apr 27, 2025
70a9e17
fix: string.gsub didn't return replace count
Akeit0 Apr 27, 2025
a880729
fix: literal parse and format
Akeit0 Apr 27, 2025
21e7000
Simplify LuaFunctionExecutionContext
Akeit0 Apr 29, 2025
168994d
make apis LuaThread Centered
Akeit0 Apr 29, 2025
abdb7f0
refactor: clean up code style and improve Lua thread handling
Akeit0 Apr 29, 2025
2633de4
api revision
Akeit0 Apr 29, 2025
2dbe7fa
fix: minus variableArgumentCount
Akeit0 Apr 29, 2025
6a65b96
move
Akeit0 Apr 29, 2025
93f7c62
fix
Akeit0 Apr 29, 2025
9f44221
Reduce LuaCoroutine Yield Resume allocation
Akeit0 Apr 30, 2025
d976dd2
Flexible LuaModule
Akeit0 Apr 30, 2025
30ca0f2
Reduced LuaModule lifetime
Akeit0 Apr 30, 2025
58ad418
small refactor
Akeit0 Apr 30, 2025
9a0eb84
revert CodeAnalysis/Syntax
Akeit0 Apr 30, 2025
7d2e974
Pool tasks used in coroutines
Akeit0 Apr 30, 2025
e60b59b
Share resume/yield core implementations
Akeit0 Apr 30, 2025
5ce0765
fix: async coroutine bug
Akeit0 Apr 30, 2025
7452141
Add LightAsyncValueTaskMethodBuilder and related types for zero alloc…
Akeit0 Apr 30, 2025
5dda75c
Lazy stack trace
Akeit0 May 1, 2025
d031777
Add: support LoadKX
Akeit0 May 2, 2025
980d527
Merge pull request #139 from nuskey8/loadkx
Akeit0 May 2, 2025
b8fed2b
Add: Add project and code to make it easier to check JIT asm
Akeit0 May 2, 2025
4ce8f59
Merge pull request #140 from nuskey8/util/vm-markers
Akeit0 May 2, 2025
ce07778
fix: remove todo work around
Akeit0 May 2, 2025
6e784f5
fix: cannot build
Akeit0 May 2, 2025
2edbf08
better jit dump
Akeit0 May 2, 2025
cf943e3
fix: handle BOM in Lua chunk loading
Akeit0 May 2, 2025
0226102
Add: implement BOM utility for encoding detection in Lua chunk loading
Akeit0 May 2, 2025
a457cb0
refactor: simplify fixed statement usage and remove unnecessary nulla…
Akeit0 May 2, 2025
d8448b7
refactor: Lua.CodeAnalysis.Compilation
Akeit0 May 3, 2025
8182a85
refactor: remove unnecessary blank lines and simplify code structure
Akeit0 May 3, 2025
a449410
fix: update chunk name handling in **File** methods to use full path
Akeit0 May 4, 2025
058de2f
change: draft of better compile exception
Akeit0 May 4, 2025
aa2d2b4
demo of rust like compile exception
Akeit0 May 4, 2025
216a08b
fix: compile error shows incorrect position and token
Akeit0 May 5, 2025
a5115fc
refactor: remove unused properties from LuaFunctionExecutionContext a…
Akeit0 May 5, 2025
8249ad4
add: Comprehensive Lua API for basic operations
Akeit0 May 5, 2025
5882dae
fix: use __call via other metamethods
Akeit0 May 6, 2025
9a25985
feat: implement OpCall method for LuaThread and fix vararg handling
Akeit0 May 6, 2025
f295651
fix: adjust argument count handling in DoFile method
Akeit0 May 6, 2025
0bbaa01
improve: improve call stack handling and exception management
Akeit0 May 8, 2025
af01bdc
change: move apis to LuaThreadAccess to validate context
Akeit0 May 10, 2025
48e18d8
fix: parser initialization order
Akeit0 May 11, 2025
d7e81d2
refactor: replace StringBuilder with FastListCore in Scanner for redu…
Akeit0 May 11, 2025
02dad70
refactor: replace FastListCore with PooledList in Scanner
Akeit0 May 11, 2025
147b498
Merge pull request #143 from nuskey8/access-validation
Akeit0 May 12, 2025
3eacaa7
Add: add Low level APIs for compilation
Akeit0 May 13, 2025
40ec053
refactor: replace File.ReadAllBytesAsync with sync to prevent uninten…
Akeit0 May 13, 2025
e80362e
improve: better error message
Akeit0 May 13, 2025
e97aefc
improve: error message
Akeit0 May 15, 2025
df5ed5c
refactor: simplify exception hierarchy by removing LuaException base …
Akeit0 May 15, 2025
f6abe52
fix: update new line detection to handle both LF and CRLF
Akeit0 May 15, 2025
59e3678
improve: enhance cancellation handling and introduce LuaCancelledExce…
Akeit0 May 15, 2025
0d72037
improve: enhance error message for LuaCancelledException
Akeit0 May 15, 2025
d36e9b8
Merge pull request #147 from nuskey8/improve-cancel
Akeit0 May 15, 2025
2b5e0a2
rename: rename LuaCancelledException to LuaCanceledException for cons…
Akeit0 May 15, 2025
d3e99c4
Improve hook check performance
Akeit0 May 16, 2025
64e415c
Add: SetHook API
Akeit0 May 16, 2025
417a890
fix: use GetArgumentOrDefault for mask in SetHook method
Akeit0 May 16, 2025
01c919f
Add: support exception handling from hook
Akeit0 May 16, 2025
19eb52e
Add: implement IEnumerable interface for LuaTable and add enumerator
Akeit0 May 17, 2025
3cd21a8
Refactor: optimize LuaTableEnumerator and extract MoveNext logic to L…
Akeit0 May 17, 2025
060e12f
Add: support passing CancellationToken in parameter by LuaObjectGener…
Akeit0 May 17, 2025
e5e7121
Add: support passing CancellationToken in parameter by LuaObjectGener…
Akeit0 May 17, 2025
97d996f
Merge remote-tracking branch 'origin/v0.5-dev' into v0.5-dev
Akeit0 May 17, 2025
930b5d9
Fix: correct async return statement in LuaObjectGenerator generated code
Akeit0 May 17, 2025
f3d299c
fix: fix LuaObjectGenerator value conversion handling
Akeit0 May 17, 2025
30c2d34
fix: add more types in SymbolReferences for Lua.SourceGenerator
Akeit0 May 17, 2025
3dc8e41
fix: prevent null startLine from causing unnecessary line append in C…
Akeit0 May 17, 2025
0070772
fix: improve indent in LuaObjectGenerator
Akeit0 May 17, 2025
627b358
fix: handle _ENV upvalue in LuaClosure
Akeit0 May 17, 2025
d17154c
fix: required return value
Akeit0 May 17, 2025
069babf
fix: call hook pc
Akeit0 May 17, 2025
8e600ba
fix: io.write
Akeit0 May 17, 2025
0491bc3
fix: rename io["stdio"] to io["stdin"]
Akeit0 May 18, 2025
947479e
fix: update io access to use registry instead of environment
Akeit0 May 18, 2025
34aaa59
fix: adjust indent in LuaObjectGenerator
Akeit0 May 18, 2025
41734dd
fix: off tailcall flag on error
Akeit0 May 18, 2025
e36d03c
fix: concat null error
Akeit0 May 18, 2025
35c654d
feat: enhance module loading and package management
Akeit0 May 18, 2025
39be24e
change: abstract async file and stream system
Akeit0 May 18, 2025
6d473fd
fix: improve LuaValue handling and simplify object conversion
Akeit0 May 18, 2025
1c778d2
rename: rename LoadModuleAsync to ReadFileAsync
Akeit0 May 18, 2025
bf1e2d8
rename: rename LuaFile to LuaFileContent and update related methods
Akeit0 May 18, 2025
c784577
rename: rename ILuaFileManager to ILuaFileSystem and update references
Akeit0 May 19, 2025
e75c81b
rename: update FileManager references to FileSystem in OperatingSyste…
Akeit0 May 19, 2025
2403e5b
change: move file systems to Lua.IO
Akeit0 May 19, 2025
5278982
refactor: rename SystemStream references to StreamWrapper
Akeit0 May 19, 2025
95e1c80
refactor: update ReadByteAsync to ReadStringAsync and simplify Seek m…
Akeit0 May 20, 2025
f25d1aa
refactor: simplify FileHandle by removing reader/writer and using ISt…
Akeit0 May 20, 2025
3ef61e3
refactor: update file opening methods to use LuaFileMode and simplify…
Akeit0 May 20, 2025
fa2c90d
refactor: rename LuaFileMode to LuaFileOpenMode
Akeit0 May 20, 2025
12413f3
change: update Open method to include throwError parameter for error …
Akeit0 May 20, 2025
0cf2eca
feat: add GetTempFileName method to ILuaFileSystem and update TmpName…
Akeit0 May 20, 2025
89d6ce7
reformat
Akeit0 May 20, 2025
060ee0f
feat: add DirectorySeparator property to ILuaFileSystem
Akeit0 May 20, 2025
5199f2f
fix: FileHandle.Read
Akeit0 May 20, 2025
299ab4d
rename: rename IStream to ILuaIOStream
Akeit0 May 20, 2025
0d65bce
refactor: remove unused members from ILuaFileSystem interface
Akeit0 May 20, 2025
f499aef
feat: implement enum LuaFileBufferingMode for SetVBuf method
Akeit0 May 20, 2025
e9c4b27
test: add abstract file read tests
Akeit0 May 20, 2025
2ef8081
fix: io exception was not thrown well
Akeit0 May 21, 2025
ca04ade
add: io.tmpfile
Akeit0 May 21, 2025
3b655f3
fix: compile error
Akeit0 May 21, 2025
fd686da
fix : ILuaIOStream open mode behavior
Akeit0 May 21, 2025
c72b8b5
fix: FileSystem.OpenTempFileStream is not used
Akeit0 May 21, 2025
c7e3e8c
fix: fix LuaRuntimeException handling from other exception
Akeit0 May 21, 2025
ecdf1a8
fix: update io module to include stdin, stdout, and stderr
Akeit0 May 21, 2025
678a2fe
change to throw open error always
Akeit0 May 21, 2025
705856e
fix: throw open error
Akeit0 May 21, 2025
8a6a083
fix: test compile error
Akeit0 May 21, 2025
5c19191
fix: LuaFileBufferingMode order for c compatibility
Akeit0 May 21, 2025
d6ceabf
Merge branch 'v0.5-dev' into file-system
Akeit0 May 21, 2025
772d71e
fix: io registry field naming std -> _IO_
Akeit0 May 21, 2025
46df7d6
Merge remote-tracking branch 'origin/file-system' into file-system
Akeit0 May 21, 2025
8104c0b
fix: flush was not called on close
Akeit0 May 22, 2025
d48f616
Merge pull request #149 from nuskey8/file-system
Akeit0 May 24, 2025
0d18be2
refactor: rename opcode methods for clarity
Akeit0 May 24, 2025
b494732
change: handle null userData in FromUserData method
Akeit0 May 25, 2025
4a7cfb1
fix: handle invalid operations on nil values in Lua table access
Akeit0 May 31, 2025
92ba39a
improve test log for LuaTests
Akeit0 May 31, 2025
65c593f
fix: improve error handling for invalid values in Lua table access
Akeit0 May 31, 2025
25f0385
fix: error message LuaValueType
Akeit0 May 31, 2025
b480c11
improve: error message (function name)
Akeit0 May 31, 2025
274ba80
Add: Tracebacks.FirstLine
Akeit0 May 31, 2025
3f96f9b
fix: enhance BadArgument error handling with expected types
Akeit0 May 31, 2025
3094641
fix: enhance BadArgument message
Akeit0 May 31, 2025
80e994c
fix: self BadArgument
Akeit0 May 31, 2025
f90e9a7
fix: table.sort invalid access
Akeit0 May 31, 2025
99bcf5e
fix: from C# call error message
Akeit0 May 31, 2025
5bd13ca
add: add string.match but throws NotImplementedException
Akeit0 May 31, 2025
1ec185c
fix: GetTabUp/SetTabUp error message
Akeit0 Jun 1, 2025
912dd9a
fix: string %q format with number
Akeit0 Jun 1, 2025
1b4b0a2
remove FileHandle TODO comment about optimization
Akeit0 Jun 1, 2025
94b14c5
implement LuaFileContent error message
Akeit0 Jun 1, 2025
3d580f7
add: DoBytesAsync for utf8 DoString
Akeit0 Jun 1, 2025
52b5f0c
fix: improve exception message formatting in LuaTests
Akeit0 Jun 1, 2025
8521825
add: implement MatchState for advanced string pattern matching
Akeit0 Jun 2, 2025
6353112
Merge pull request #161 from nuskey8/string-match
Akeit0 Jun 2, 2025
9e5b006
fix: enhance string pattern matching Empty pattern case
Akeit0 Jun 2, 2025
3f6acf5
fix: very large case
Akeit0 Jun 2, 2025
a2967cd
improve: error message behavior
Akeit0 Jun 2, 2025
d45c971
fix: forprep error
Akeit0 Jun 2, 2025
f373bb8
fix: error not nil but not string
Akeit0 Jun 2, 2025
0c89c0c
fix: stack overflow error
Akeit0 Jun 2, 2025
f9136ff
fix: PatternMatchingTests
Akeit0 Jun 2, 2025
61ae9eb
fix: table.concat
Akeit0 Jun 2, 2025
8690ab6
change: add ByteArrayData for binary mode
Akeit0 Jun 3, 2025
db8b4f7
change: rename ByteArrayData to BinaryData and change binary data han…
Akeit0 Jun 4, 2025
53c34de
refactor LuaChunkStream
Akeit0 Jun 4, 2025
7ab67a8
Merge pull request #162 from nuskey8/allow-bytes
Akeit0 Jun 4, 2025
2972fb9
fix: update LuaFileContentType handling and improve ReadAllAsync method
Akeit0 Jun 4, 2025
4e7b4c1
add: stdio and os abstractions
Akeit0 Jun 4, 2025
b5b7fd2
Merge pull request #163 from nuskey8/operating-system
Akeit0 Jun 4, 2025
c6ceb50
add ILuaPlatform
Akeit0 Jun 4, 2025
8fbbf41
optimize: reduce async in LuaThreadAccessAccessExtensions
Akeit0 Jun 4, 2025
a64e9cc
fix
Akeit0 Jun 4, 2025
14fed24
rename: TopLevelAccess to RootAccess
Akeit0 Jun 4, 2025
096dadb
fix: initialize string S in Token class
Akeit0 Jun 4, 2025
4a08b48
fix: rename with existing target path
Akeit0 Jun 4, 2025
0d78338
change : allow BinaryLuaIOStream to write string
Akeit0 Jun 5, 2025
20305f4
add: MemoryStreams
Akeit0 Jun 5, 2025
0df1078
add Claude Code instruction
Akeit0 Jun 5, 2025
aab98fd
migrate to slnx
Akeit0 Jun 5, 2025
a76a768
refactor: LuaFileMode and ILuaIOStream
Akeit0 Jun 5, 2025
7132f3d
improve os
Akeit0 Jun 5, 2025
953d5d5
Major refactoring of LuaPlatform
Akeit0 Jun 7, 2025
a6abf6c
LuaChunkStream public to internal
Akeit0 Jun 7, 2025
8b4d5f8
fix:v undump
Akeit0 Jun 7, 2025
65a18e8
change :CompositeLoaderFileSystem parameter order
Akeit0 Jun 7, 2025
8ea87b5
refactor: update return type of LoadAsync in ILuaFileLoader
Akeit0 Jun 7, 2025
2626e45
revert allows bytes
Akeit0 Jun 12, 2025
f023db3
Merge pull request #169 from nuskey8/revert-bytes
Akeit0 Jun 12, 2025
014b453
Support file:read("*n") and fix apis.
Akeit0 Jun 12, 2025
e7d7090
change : move time abstractions to TimeProvider
Akeit0 Jun 14, 2025
b4b9c29
reformat
Akeit0 Jun 14, 2025
0e8e56d
change : close file with async
Akeit0 Jun 14, 2025
6ca736d
update : Lua.Unity reference v0.5
Akeit0 Jun 14, 2025
ca2582a
Merge pull request #171 from nuskey8/unity-lua-v0.5
Akeit0 Jun 14, 2025
82eb4ee
fix : update Exists method to use logical OR for module checks
Akeit0 Jun 14, 2025
9280fca
Merge remote-tracking branch 'origin/v0.5-dev' into v0.5-dev
Akeit0 Jun 14, 2025
0a9bbfc
add: luac asset
Akeit0 Jun 14, 2025
9977863
change: update Traceback skip behavior
Akeit0 Jun 14, 2025
4d47f87
change : rename and make CreateTracebackMessage public
Akeit0 Jun 14, 2025
2fb499d
add: Traceback.CreateTracebackMessage
Akeit0 Jun 14, 2025
f8bb532
add : FileSystem.BaseDirectory
Akeit0 Jun 14, 2025
e3c3ef1
fix: FileSystem.GetFullPath
Akeit0 Jun 14, 2025
88ea493
Fix: missing TimeProvider type.
Akeit0 Jun 15, 2025
2d53c89
update: lua.unity dependencies
Akeit0 Jun 15, 2025
f37fdcf
change: loaded module returns better chunk name
Akeit0 Jun 20, 2025
40a1893
Merge pull request #173 from nuskey8/lua-unity-better-path
Akeit0 Jun 20, 2025
6ea0a15
remove: simulated console read methods from UnityStandardIO
Akeit0 Jun 23, 2025
f150f12
change: update class visibility from public to internal in BomUtility…
Akeit0 Jun 25, 2025
1712b45
Merge pull request #175 from nuskey8/api-internal
Akeit0 Jun 25, 2025
ca60064
change: update class visibility of DummyInputStream from public to in…
Akeit0 Jun 25, 2025
0f179ff
Merge pull request #177 from nuskey8/dummy-input-stream-internal
Akeit0 Jun 25, 2025
e3fb1a0
refactor: rename LuaCompiler.UnDump to Prototype.FromByteCode and mov…
Akeit0 Jun 29, 2025
82c72fd
Merge pull request #178 from nuskey8/byte-code-api-to-proto
Akeit0 Jun 29, 2025
0ab6270
change: rename some Do*Async methods to ExecuteAsync
Akeit0 Jun 29, 2025
c49122d
add: implement LuaThreadAssetExtensions for executing Lua assets
Akeit0 Jun 29, 2025
d8213be
Merge pull request #179 from nuskey8/execute-api
Akeit0 Jun 29, 2025
f1ae1f8
change: rename ReadReturnValues to ReadTopValues and update references
Akeit0 Jun 29, 2025
35e2c6e
Merge pull request #180 from nuskey8/return-values-to-top-values
Akeit0 Jun 29, 2025
1a44155
refactor: simplify search logic in StringLibrary by removing redundan…
Akeit0 Jul 1, 2025
44beb9d
change: rename RentUseThread to RentUserThread (typo)
Akeit0 Jul 8, 2025
fd6c2f9
fix: the results stored memory was also Cleared
Akeit0 Jul 12, 2025
10af33c
Merge pull request #187 from nuskey8/fix-clear-results
Akeit0 Jul 12, 2025
a20cc28
fix: adjust LuaTable initialization and fix remove method argument va…
Akeit0 Jul 12, 2025
dd03393
Merge pull request #188 from nuskey8/fix-tab-remove-and-initial-size
Akeit0 Jul 12, 2025
6254785
fix: array clearing in LuaTable.Clear
Akeit0 Jul 12, 2025
b42ad7e
Merge pull request #189 from nuskey8/clear-array
Akeit0 Jul 12, 2025
5260a3a
fix: update CreateMessage and WriteLastLuaTrace to use error level pa…
Akeit0 Jul 12, 2025
b2e7cd2
fix: format WriteLastLuaTrace method parameters for consistency
Akeit0 Jul 12, 2025
e991752
fix: add separator to formatted output in Tracebacks
Akeit0 Jul 12, 2025
71d1ea4
Merge pull request #190 from nuskey8/fix-error-level
Akeit0 Jul 12, 2025
ec9783b
fix: unintended stack clear
Akeit0 Jul 12, 2025
48411ed
refactor: change editorconfig and cleanup code
Akeit0 Jul 27, 2025
cb9ac66
Change: LuaState to LuaGlobalState, LuaThread to LuaState
Akeit0 Jul 27, 2025
ceec702
change: remove LuaThreadAccess and Rename LuaThread to LuaState LuaSt…
Akeit0 Aug 2, 2025
dd64efe
refactor: rename LuaState parameter to improve clarity
Akeit0 Aug 2, 2025
d07bd4d
feat: add methods to create threads and coroutines in LuaState
Akeit0 Aug 2, 2025
b9821f4
change: simplify platform access api
Akeit0 Aug 2, 2025
098db5c
revert README.md
Akeit0 Aug 2, 2025
e69387c
fix: enable benchmarking for MoonSharp and NLua file execution
Akeit0 Aug 3, 2025
2a78b99
Change: change GlobalState to internal
Akeit0 Aug 16, 2025
d2eef68
Merge pull request #203 from nuskey8/simplyfy-lua-state
Akeit0 Aug 23, 2025
2d77780
introduce StringInternPool.cs to reduce allocation and seq comp
Akeit0 Aug 23, 2025
41eb3a8
Merge pull request #211 from nuskey8/string-intern-pool
Akeit0 Aug 23, 2025
ff51891
fix: utf8 bom skip
Akeit0 Aug 24, 2025
ec7842f
chore: format source code
nuskey8 Nov 11, 2025
639a08b
refactor: reuse LuaPlatform.Default
Akeit0 Nov 15, 2025
0129b55
rename: ByteCode to Bytecode
Akeit0 Nov 15, 2025
c2c5bfb
rename: UnDump to Undump
Akeit0 Nov 15, 2025
0d9e1d2
rename: TopValues to Stack
Akeit0 Nov 15, 2025
bfe9016
rename: LuaUnDumpException to LuaUndumpException
Akeit0 Nov 15, 2025
f79a618
rename: add async suffix to operator apis
Akeit0 Nov 15, 2025
bb3d078
refactor: add sealed, static, etc.
nuskey8 Nov 16, 2025
2121504
fix: compilation error in Unity sandbox
nuskey8 Nov 16, 2025
71a50c4
chore: bump up JitInspect package
nuskey8 Nov 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"permissions": {
"allow": [
"Bash(dotnet build:*)",
"Bash(dotnet run:*)"
],
"deny": []
}
}
28 changes: 14 additions & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members
dotnet_style_require_accessibility_modifiers = omit_if_default

# Expression-level preferences
dotnet_style_coalesce_expression = true
Expand Down Expand Up @@ -77,9 +77,9 @@ dotnet_style_allow_statement_immediately_after_block_experimental = true
#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false
csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = false
csharp_style_var_elsewhere = true
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true

# Expression-bodied members
csharp_style_expression_bodied_accessors = true
Expand All @@ -104,14 +104,14 @@ csharp_style_conditional_delegate_call = true

# Modifier preferences
csharp_prefer_static_local_function = true
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async
csharp_preferred_modifier_order = public, private, protected, internal, file, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, required, volatile, async
csharp_style_prefer_readonly_struct = true
csharp_style_prefer_readonly_struct_member = true

# Code-block preferences
csharp_prefer_braces = true
csharp_prefer_simple_using_statement = true
csharp_style_namespace_declarations = block_scoped
csharp_style_namespace_declarations = file_scoped
csharp_style_prefer_method_group_conversion = true
csharp_style_prefer_primary_constructors = true
csharp_style_prefer_top_level_statements = true
Expand Down Expand Up @@ -208,26 +208,26 @@ dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.types.required_modifiers =
dotnet_naming_symbols.types.required_modifiers =

dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =
dotnet_naming_symbols.non_field_members.required_modifiers =

# Naming styles

dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.required_prefix =
dotnet_naming_style.pascal_case.required_suffix =
dotnet_naming_style.pascal_case.word_separator =
dotnet_naming_style.pascal_case.capitalization = pascal_case

dotnet_naming_style.begins_with_i.required_prefix = I
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.required_suffix =
dotnet_naming_style.begins_with_i.word_separator =
dotnet_naming_style.begins_with_i.capitalization = pascal_case


Expand Down
126 changes: 126 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Lua-CSharp is a high-performance Lua interpreter implemented in C# for .NET and Unity. It provides a Lua 5.2 interpreter with async/await integration, Source Generator support for easy C#-Lua interop, and Unity support.

## Common Development Commands

### Building
```bash
# Build entire solution
dotnet build

# Build in Release mode
dotnet build -c Release

# Build specific project
dotnet build src/Lua/Lua.csproj
```
### Running

Write lua to `sandbox/ConsoleApp1/test.lua`, then:
```bash
# Run simple tests
dotnet run --project sandbox/ConsoleApp1/ConsoleApp1.csproj

# For pattern matching testing, you can run specific Lua scripts like:
# echo 'print(string.gsub("hello", "()l", function(pos) return "[" .. pos .. "]" end))' > sandbox/ConsoleApp1/test.lua
# echo 'print(string.gsub("abc", "", "."))' > sandbox/ConsoleApp1/test.lua
# echo 'print(string.gsub("(hello) and (world)", "%b()", function(s) return s:upper() end))' > sandbox/ConsoleApp1/test.lua
```


### Testing
```bash
# Run all tests
dotnet test

# Run tests with detailed output
dotnet test --logger "console;verbosity=detailed"

# Run specific test project
dotnet test tests/Lua.Tests/Lua.Tests.csproj
```

### Benchmarking
```bash
# Run performance benchmarks
dotnet run -c Release --project sandbox/Benchmark/Benchmark.csproj
```

### Packaging
```bash
# Create NuGet package
dotnet pack -c Release
```

## Architecture Overview

### Core Components

1. **Lua Runtime (`src/Lua/`)**
- `LuaState.cs`: Main entry point for Lua execution
- `LuaValue.cs`: Represents values in Lua (nil, boolean, number, string, table, function, userdata, thread)
- `Runtime/LuaVirtualMachine.cs`: Core VM implementation that executes Lua bytecode
- `Runtime/OpCode.cs`, `Runtime/Instruction.cs`: VM instruction definitions
- `CodeAnalysis/`: Lexer, parser, and compiler that converts Lua source to bytecode

2. **Source Generator (`src/Lua.SourceGenerator/`)**
- Generates code for classes marked with `[LuaObject]` attribute
- Enables seamless C#-Lua interop by auto-generating wrapper code
- Key file: `LuaObjectGenerator.cs`

3. **Standard Libraries (`src/Lua/Standard/`)**
- Implementations of Lua standard libraries (math, string, table, io, etc.)
- Entry point: `OpenLibsExtensions.cs`

### Key Design Patterns

1. **Async/Await Integration**
- All Lua execution methods are async (`DoStringAsync`, `DoFileAsync`)
- LuaFunction can wrap async C# methods
- Enables non-blocking execution of Lua scripts

2. **Value Representation**
- `LuaValue` is a discriminated union struct
- Implicit conversions between C# and Lua types
- Zero-allocation for primitive types

3**Memory Management**
- Heavy use of object pooling (`Pool.cs`, `PooledArray.cs`, `PooledList.cs`)
- Stack-based value types where possible
- Careful management of closures and upvalues

### Unity Integration (`src/Lua.Unity/`)

- Custom asset importer for `.lua` files
- Integration with Unity's Resources and Addressables systems
- Works with both Mono and IL2CPP

### Testing Structure

- Unit tests in `tests/Lua.Tests/`
- Lua test suite from official Lua 5.2 in `tests/Lua.Tests/tests-lua/`
- Benchmarks comparing with MoonSharp and NLua in `sandbox/Benchmark/`

## Important Notes

- The project targets .NET Standard 2.1, .NET 6.0, and .NET 8.0
- Uses C# 13 language features
- Heavy use of unsafe code for performance
- Strings are UTF-16 (differs from standard Lua)

## TODO

- **ILuaStream Interface Changes**: The ILuaStream interface has been updated with new methods:
- Added `IsOpen` property to track stream state
- Added `ReadNumberAsync()` for reading numeric values (supports formats like "6.0", "-3.23", "15e12", hex numbers)
- Changed `ReadLineAsync()` to accept a `keepEol` parameter for controlling line ending behavior
- Renamed `ReadStringAsync()` to `ReadAsync()`
- Added `CloseAsync()` method for async stream closing
- ✅ Implemented `ReadNumberAsync()` in all implementations
- Need to properly implement the `keepEol` parameter in `ReadLineAsync()` for TextLuaStream
59 changes: 0 additions & 59 deletions Lua.sln

This file was deleted.

16 changes: 16 additions & 0 deletions Lua.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Solution>
<Folder Name="/sandbox/">
<File Path="sandbox/ConsoleApp2/.gitignore"/>
<Project Path="sandbox/Benchmark/Benchmark.csproj"/>
<Project Path="sandbox/ConsoleApp1/ConsoleApp1.csproj"/>
<Project Path="sandbox/ConsoleApp2/ConsoleApp2.csproj"/>
<Project Path="sandbox/JitTest/JitTest.csproj"/>
</Folder>
<Folder Name="/src/">
<Project Path="src/Lua.SourceGenerator/Lua.SourceGenerator.csproj"/>
<Project Path="src/Lua/Lua.csproj"/>
</Folder>
<Folder Name="/tests/">
<Project Path="tests/Lua.Tests/Lua.Tests.csproj"/>
</Folder>
</Solution>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,4 +552,4 @@ While `collectgarbage()` is available, it simply calls the corresponding .NET ga

## License

Lua-CSharp is licensed under the [MIT License](LICENSE).
Lua-CSharp is licensed under the [MIT License](LICENSE).
7 changes: 4 additions & 3 deletions sandbox/Benchmark/AddBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ public void Setup()
core.Setup("add.lua");
core.LuaCSharpState.OpenStandardLibraries();

core.LuaCSharpState.Environment["add"] = new LuaFunction("add", (context, buffer, ct) =>
core.LuaCSharpState.Environment["add"] = new LuaFunction("add", (context, ct) =>
{
buffer.Span[0] = context.GetArgument<double>(0) + context.GetArgument<double>(1);
return new(1);
var a = context.GetArgument<double>(0);
var b = context.GetArgument<double>(1);
return new(context.Return(a + b));
});
core.MoonSharpState.Globals["add"] = (Func<double, double, double>)Add;
core.NLuaState.RegisterFunction("add", typeof(AddBenchmark).GetMethod(nameof(Add), BindingFlags.Static | BindingFlags.Public));
Expand Down
28 changes: 14 additions & 14 deletions sandbox/Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="MoonSharp" Version="2.0.0" />
<PackageReference Include="NLua" Version="1.7.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0"/>
<PackageReference Include="MoonSharp" Version="2.0.0"/>
<PackageReference Include="NLua" Version="1.7.3"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Lua\Lua.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Lua\Lua.csproj"/>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion sandbox/Benchmark/BenchmarkCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class BenchmarkCore : IDisposable
public void Setup(string fileName)
{
// moonsharp
moonSharpState = new Script();
moonSharpState = new();
Script.WarmUp();

// NLua
Expand Down
40 changes: 40 additions & 0 deletions sandbox/Benchmark/HookedBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using BenchmarkDotNet.Attributes;
using Lua;
using Lua.Standard;

[Config(typeof(BenchmarkConfig))]
public class HookedBenchmark
{
BenchmarkCore core = default!;
LuaValue[] buffer = new LuaValue[1];

[IterationSetup]
public void Setup()
{
core = new();
core.Setup("hooked.lua");
core.LuaCSharpState.OpenStandardLibraries();
}

[IterationCleanup]
public void Cleanup()
{
core.Dispose();
core = default!;
GC.Collect();
}


[Benchmark(Description = "NLua (DoString)", Baseline = true)]
public object[] Benchmark_NLua_String()
{
return core.NLuaState.DoString(core.SourceText);
}

[Benchmark(Description = "Lua-CSharp (DoString)")]
public async Task<LuaValue> Benchmark_LuaCSharp_String()
{
await core.LuaCSharpState.DoStringAsync(core.SourceText, buffer);
return buffer[0];
}
}
Loading