Generate code in C - binding

I've got a library in C that I'd like to generate bindings for in Elisp. In Ruby, I'd simply include a header and then use its C API to generate functions and so on. Can I do the same on elisp? describe-function often says that a function is in "C source code". How are these generated?
Thanks!

You can check this Emacs doc to see how to wrap C function into a DEFUN macro to make it accessible from Emacs.
Once primitives are defined you need to recompile Emacs, you cannot load them dynamically in the runtime.

Related

Call into Lua from TI-BASIC

I have an nspire calculator and after writing a hash table implementation, found the BASIC environment to be a pretty offensive programming environment. Unfortunately, as far as I'm aware, it's impossible to use Lua to write libraries.
I did see that somewhere in the Lua interface you can detect variable changes so it might be possible within a file to use Lua functions, but I fear it will go out of scope if used externally.
Is there a better way to do this?
It's not impossible to write Lua libraries for a TI-Nspire. You can put the libraries code into a string, store it as a variable in TI-Basic and put the file in the MyLibs folder. Then, when you want to load your library, do loadstring(var.recall("libfilename/programstring"))(). This will load the library's code as a string from that files, compile it (using loadstring), and execute it (practicaly the same as require).
Also, about getting from controlling a Lua script using TI-Basic, depending on what you want to do, you could use math.eval("<some TI-Basic code>"). This will execute the code in TI-Basic, and return the result as a Lua value (or string). This way, you can call a TI-Basic function every once in a while, and act according to its output.

gen_bridge_support ignores variadic functions

I'm trying to use a c library in RubyMotion, and in order to call out to functions in the library I need to generate a bridgesupport file. RubyMotion is requesting the generation of this file, but I can see that not a single variadic function from the library appears in the bridgesupport file. I've tried walking through the source of gen_bridge_metadata, but in the end it calls out to a parser in a shared object lib so I can't get much further than that. All I can see is that it's not declaring an AFunctionDecl for that function.
Are variadic functions just not supported full stop, or is there some sort of config that I need to apply somewhere?
So this appears to be caused by not having all the .h and .a files for the library and it's dependencies together in the same directories. Eg. I had:
/vendor/lib1
/vendor/lib2
/vendor/lib3
when I should have had
/vendor/lib3 (containing all of lib1 + lib2 as well)

retrieving the module object on Lua

I have a C program that uses Lua to run some scripts. I need to open the Lua libraries via C code like luaopen_socket_core(myLuaState), for some reasons I can't load the modules from the Lua code, like socket = require "luasocket".
Once understood the idea of this program now I need to load a library called struct, so I added the struct.c to my project, and when I tried to use its functions like struct.unpack the runtimer complains that there is no global variable called struct. Of course it was loaded with luaopen_struct(myLuaState) instead of struct = require "struct" which is forbidden for me.
Any suggestion about an way of having this struct variable available?
Take a look at luaL_requiref in the auxiliary library, which mimics require called from Lua.
You probably called the open-function directly and forgot to set those variables manually, that function would do it all for you.

How can I tell if a module is being called dynamically or statically?

How can I tell if a module is being called dynamically or statically?
If you are operating on z/OS, you can accomplish this, but it is non-trivial.
First, you must trace up the save area chain and use CSVQUERY to find out which program owns each save area. Every other program will be a Cobol runtime module, like IGZCPAC. Under IMS, CICS, TSO, et al, those modules might be different. That is the easy part.
Once you know who owns all the relevant save areas, you can use the OS LOADER / BINDER / LINKER utilities to discover what artifacts are in the same modules. This is the non-easy part.
The ONLY way is to look at the output of the linkage editor (IEWL) or the load module itself. If the module is being called DYNAMICALLY then it will not exist in the main module, if it is being called STATICALLY then it will be seen in the load module. Calling a working storage variable, containing a program name, does not make a DYNAMIC call. This type of calling is known as IMPLICITE calling as the name of the module is implied by the contents of the working storage variable. Calling a program name literal.
Calling a working storage variable,
containing a program name, does not
make a DYNAMIC call.
Yes it does. Call variablename is always DYNAMIC.
Call 'literal' is dynamic or static according to the DYNAM/NODYNAM compiler option.
Caveat: This applies for IBM mainframe COBOL and I believe it is also part of the standard. It may not apply to other non-standard versions of COBOL.
For Micro Focus COBOL statically linking is controlled via call-convention on the call (bit 3) or via the compiler directive LITLINK.
When linking statically the case of the program-id/entry-point and the call itself is important, so you may want to ensure it is exact and use the CASE directive.
The reverse of LITLINK directive is the NOLITLINK directive or a call-convention without bit 3 set!
On Windows you can see the exported symbols in your .dll by using the "dumpbin /exports" utility and on Unix via the 'nm' utility.
A import .lib for the .dll created via "cbllink" can be created by using the '-K'command line option on cbllink.
Look at the call statement. If the called program is described in a literal then it's a static call. It's called a dynamic call if the called program is determined at runtime:
* Static call
call "THEPROGRAM"
* Dynamic call
call wsProgramName

Komodo Edit: How to do some of these basic Macro and Snippet operations?

I am wondering how to do (or where to find documentation) on these basic
macro and snippet operations in Komodo Edit.
1) FILE/IO: write a string to a temporary file from within a komodo javascript macro
2) FILE/IO: read the content of a text file into a string within a komodo javascript macro
3) INCLUDES: cross-reference local javascript "include" libraries within a macro,
or something equivalent to #script src="~/mylocal_javascript_addons.js" So I can consolidate macro code.
4) SNIPPET_OUTPUT: create a snippet interpolation placeholder that returns the output of a
user-defined javascript function or macro.
For example:
[[%(myscript:SayHelloWorld())]]
[[%(foomacro-MyAgeInMilliseconds)]]
5) MACRO_OUTPUT: macro that takes a multiple-line selection in the current buffer and passes
it to a local script or batch file, and then replaces the selection with the output
result. (Need a way to do this in MSFT Windows, not just linux).
If you can answer one or more of these using Python instead of Javascript, that's great, but please include sample code or a link to it, because the Python documentation seems to be extremely TODO.
Don't have your answers, but you might have more luck asking here:
http://community.activestate.com/forums/komodo-extensions

Resources