Skip to content

Commit

Permalink
add utility to get the size of a file in bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
lichendust committed Jul 25, 2024
1 parent fa3287b commit 563281e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions spindle.odin
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ execute_spindle :: proc(args: []string, is_prod: bool) {

register_procedure(ctx, "set_working_directory", lua_set_working_directory)
register_procedure(ctx, "get_working_directory", lua_get_working_directory)
register_procedure(ctx, "size_of_file", lua_size_of_file)

// @note what is this? who put this here? I know it was me but why??
register_procedure(ctx, "_balance_parens", lua_balance_parentheses)
Expand Down Expand Up @@ -590,6 +591,16 @@ lua_get_working_directory :: proc "c" (ctx: ^lua.State) -> i32 {
return 1
}

lua_size_of_file :: proc "c" (ctx: ^lua.State) -> i32 {
context = runtime.default_context()

file := strings.clone_from_cstring(lua.L_checkstring(ctx, 1), context.temp_allocator)
size := os.file_size_from_path(file)

lua.pushinteger(ctx, cast(lua.Integer) size)
return 1
}

USAGE :: SPINDLE + `
spindle [command] <flags>
Expand Down

0 comments on commit 563281e

Please sign in to comment.