-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
-- Include this file to get have the global "arg" | ||
-- with your program command line arguments. | ||
|
||
## if pragmas.nogc then | ||
|
||
require 'span' | ||
|
||
global arg: span(cstring) | ||
|
||
local function nelua_main(): cint <cimport,nodecl> end | ||
|
||
local function main(argc: cint, argv: cchar**): cint <entrypoint> | ||
arg = {data=argv, size=argc} | ||
return nelua_main() | ||
-- filled with your program command line arguments. | ||
|
||
require 'sequence' | ||
require 'allocators.general' | ||
|
||
-- Import argc and argv from C 'nelua_main' | ||
local nelua_argc: cint <cimport, nodecl> | ||
local nelua_argv: cstring[0]* <cimport, nodecl> | ||
|
||
-- List of command line arguments. | ||
-- The index 0 usually is filled with the program executable. | ||
-- The arguments goes from 1 up to #arg (like in Lua). | ||
global arg: sequence(stringview, GeneralAllocator) | ||
|
||
do -- setup args | ||
local narg: usize = (@usize)(nelua_argc-1) | ||
arg:reserve(narg) | ||
for i:usize=0,narg do | ||
arg[i] = nelua_argv[i] | ||
end | ||
end | ||
|
||
## else | ||
|
||
require 'allocators.gc' | ||
|
||
## end | ||
-- NOTE: the memory of 'arg' is never freed, | ||
-- but this is fine, is not a leak for global variables. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters