luaur_compiler/functions/
set_compile_constant_string.rs1use crate::enums::type_constant_folding::Type;
2use crate::records::compile_error::CompileError;
3use crate::records::constant::Constant;
4use crate::type_aliases::compile_constant::CompileConstant;
5use core::ffi::c_char;
6use core::ffi::c_uint;
7use luaur_ast::records::location::Location;
8
9pub fn set_compile_constant_string(constant: CompileConstant, s: *const c_char, l: usize) {
10 let target = constant as *mut Constant;
11
12 if l > c_uint::MAX as usize {
13 CompileError::raise(
14 &Location::default(),
15 format_args!("Exceeded custom string constant length limit"),
16 );
17 }
18
19 unsafe {
20 (*target).r#type = Type::Type_String;
21 (*target).string_length = l as c_uint;
22 (*target).data.value_string = s;
23 }
24}