c import
This commit is contained in:
10
examples/issue-0019/c_wrapper.sx
Normal file
10
examples/issue-0019/c_wrapper.sx
Normal file
@@ -0,0 +1,10 @@
|
||||
// This module imports C functions and provides wrappers
|
||||
#import c {
|
||||
#include "vendors/test_c/test.h";
|
||||
#source "vendors/test_c/test.c";
|
||||
};
|
||||
|
||||
// Wrapper function that calls the C function
|
||||
wrapped_add :: (a: s32, b: s32) -> s32 {
|
||||
add_numbers(a, b);
|
||||
}
|
||||
18
examples/issue-0019/main_bad.sx
Normal file
18
examples/issue-0019/main_bad.sx
Normal file
@@ -0,0 +1,18 @@
|
||||
// Test: other.sx calls C functions without importing the C module
|
||||
// main imports both c_wrapper.sx and other.sx
|
||||
// other.sx should NOT have access to C functions from c_wrapper
|
||||
#import "../modules/std.sx";
|
||||
#import "c_wrapper.sx";
|
||||
#import "other.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
// This works: we import c_wrapper so we have transitive access
|
||||
result := wrapped_add(10, 20);
|
||||
print("wrapped_add(10, 20) = {}\n", result);
|
||||
|
||||
// This calls other.sx's function which tries to call add_numbers
|
||||
// other.sx did NOT import c_wrapper.sx, so this should fail
|
||||
bad := use_c_directly();
|
||||
print("use_c_directly() = {}\n", bad);
|
||||
0;
|
||||
}
|
||||
10
examples/issue-0019/main_good.sx
Normal file
10
examples/issue-0019/main_good.sx
Normal file
@@ -0,0 +1,10 @@
|
||||
// Test: calling wrapper functions works (we import the module)
|
||||
#import "../modules/std.sx";
|
||||
#import "c_wrapper.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
// This should work: calling the sx wrapper
|
||||
result := wrapped_add(10, 20);
|
||||
print("wrapped_add(10, 20) = {}\n", result);
|
||||
0;
|
||||
}
|
||||
6
examples/issue-0019/other.sx
Normal file
6
examples/issue-0019/other.sx
Normal file
@@ -0,0 +1,6 @@
|
||||
// This file does NOT import c_wrapper.sx
|
||||
// It should NOT be able to call add_numbers
|
||||
|
||||
use_c_directly :: () -> s32 {
|
||||
add_numbers(5, 3);
|
||||
}
|
||||
Reference in New Issue
Block a user