github.com/goplus/llgo@v0.8.3/py/module.go (about)

     1  /*
     2   * Copyright (c) 2024 The GoPlus Authors (goplus.org). All rights reserved.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package py
    18  
    19  import (
    20  	_ "unsafe"
    21  
    22  	"github.com/goplus/llgo/c"
    23  )
    24  
    25  // https://docs.python.org/3/c-api/import.html
    26  // https://docs.python.org/3/c-api/module.html
    27  
    28  /*
    29  // llgo:type C
    30  type ModuleDefBase struct {
    31  	Unused [8]byte // TODO(xsw)
    32  }
    33  
    34  // llgo:type C
    35  type ModuleDef struct {
    36  	Base ModuleDefBase
    37  	// TODO(xsw)
    38  }
    39  */
    40  
    41  // Return the module object corresponding to a module name. The name argument
    42  // may be of the form package.module. First check the modules dictionary if
    43  // there’s one there, and if not, create a new one and insert it in the modules
    44  // dictionary. Return nil with an exception set on failure.
    45  //
    46  //go:linkname AddModule C.PyImport_AddModule
    47  func AddModule(name *c.Char) *Object
    48  
    49  // This is a wrapper around py.Import which takes a const char* as an argument
    50  // instead of an Object.
    51  //
    52  //go:linkname ImportModule C.PyImport_ImportModule
    53  func ImportModule(name *c.Char) *Object
    54  
    55  // This is a higher-level interface that calls the current “import hook function” (with
    56  // an explicit level of 0, meaning absolute import). It invokes the __import__() function
    57  // from the __builtins__ of the current globals. This means that the import is done using
    58  // whatever import hooks are installed in the current environment.
    59  //
    60  // This function always uses absolute imports.
    61  //
    62  //go:linkname Import C.PyImport_Import
    63  func Import(name *Object) *Object
    64  
    65  // Return the dictionary object that implements module’s namespace; this object is the same
    66  // as the __dict__ attribute of the module object. If module is not a module object (or a
    67  // subtype of a module object), SystemError is raised and nil is returned.
    68  //
    69  // It is recommended extensions use other Module and Object functions rather than directly
    70  // manipulate a module’s __dict__.
    71  //
    72  // llgo:link (*Object).ModuleGetDict C.PyModule_GetDict
    73  func (m *Object) ModuleGetDict() *Object { return nil }
    74  
    75  // llgo:link (*Object).ModuleLoadSyms C.llgoLoadPyModSyms
    76  func (m *Object) ModuleLoadSyms(__llgo_va_list ...any) {}
    77  
    78  // -----------------------------------------------------------------------------