Skip to content

Commit

Permalink
Support for global arg
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Sep 3, 2020
1 parent 6d3014d commit ef8a031
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/allocators/gc.nelua
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,12 @@ end

local function nelua_main(): cint <cimport,nodecl> end

global arg: span(cstring)

local function main(argc: cint, argv: cchar**): cint <entrypoint>
gc:start(&argc)
gc:_mark_statics()
arg = {data=argv, size=argc}
local ret: cint = nelua_main()
gc:stop()
return ret
Expand Down
21 changes: 21 additions & 0 deletions lib/arg.nelua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- 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()
end

## else

require 'allocators.gc'

## end
1 change: 1 addition & 0 deletions rockspecs/nelua-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ build = {
['lib/allocators/stack.nelua'] = 'lib/allocators/stack.nelua',
['lib/allocators/heap.nelua'] = 'lib/allocators/heap.nelua',
['lib/allocators/pool.nelua'] = 'lib/allocators/pool.nelua',
['lib/arg.nelua'] = 'lib/arg.nelua',
['lib/basic.nelua'] = 'lib/basic.nelua',
['lib/io.nelua'] = 'lib/io.nelua',
['lib/math.nelua'] = 'lib/math.nelua',
Expand Down

0 comments on commit ef8a031

Please sign in to comment.